Skip to content

Commit f57a750

Browse files
committed
Merge branch 'feat/storage' into 'master'
Core: expose cache_path See merge request TankerHQ/sdk-rust!89
2 parents 38a7175 + e80cc46 commit f57a750

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

src/core.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ impl Core {
2121
/// # use tankersdk::*;
2222
/// # async {
2323
/// let app_id = "Your tanker App ID".to_string();
24-
/// let writable_path = "/some/writable/path".to_string();
25-
/// let tanker = Core::new(Options::new(app_id, writable_path)).await?;
24+
/// let persistent_path = "/some/writable/path".to_string();
25+
/// let cache_path = "/some/cache/path".to_string();
26+
/// let tanker = Core::new(Options::new(app_id, persistent_path, cache_path)).await?;
2627
/// # Result::<(), Error>::Ok(()) };
2728
/// ```
2829
pub async fn new(options: Options) -> Result<Self, Error> {

src/ctanker.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,31 @@ impl CTankerLib {
151151

152152
let fut = {
153153
let coptions = tanker_options {
154-
version: 3,
154+
version: 4,
155155
app_id: options.app_id.as_ptr(),
156156
url: options
157157
.url
158158
.as_ref()
159159
.map(|s| s.as_ptr())
160160
.unwrap_or(std::ptr::null()),
161-
writable_path: options.writable_path.as_ptr(),
161+
persistent_path: options.persistent_path.as_ptr(),
162+
cache_path: options.cache_path.as_ptr(),
162163
sdk_type: sdk_type.as_ptr(),
163164
sdk_version: sdk_version.as_ptr(),
164-
http_send_request: None,
165-
http_cancel_request: None,
166-
http_data: std::ptr::null_mut(),
165+
http_options: tanker_http_options {
166+
send_request: None,
167+
cancel_request: None,
168+
data: std::ptr::null_mut(),
169+
},
170+
datastore_options: tanker_datastore_options {
171+
open: None,
172+
close: None,
173+
nuke: None,
174+
put_serialized_device: None,
175+
find_serialized_device: None,
176+
put_cache_values: None,
177+
find_cache_values: None,
178+
},
167179
};
168180
unsafe { CFuture::new(tanker_call!(self, tanker_create(&coptions))) }
169181
};

src/types.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ use std::fmt::{Display, Formatter};
1010
pub struct Options {
1111
pub(crate) url: Option<CString>,
1212
pub(crate) app_id: CString,
13-
pub(crate) writable_path: CString,
13+
pub(crate) persistent_path: CString,
14+
pub(crate) cache_path: CString,
1415
pub(crate) sdk_type: Option<CString>,
1516
}
1617

1718
impl Options {
1819
/// # Arguments
1920
/// * `app_id` - Your Tanker App ID
20-
/// * `writable_path` - A writable folder. Tanker will use this folder to
21+
/// * `persistent_path` - A writable folder. Tanker will use this folder to
2122
/// store persistent data about user sessions on the current device.
22-
pub fn new(app_id: String, writable_path: String) -> Self {
23+
/// * `cache_path` - A writable folder. Tanker will use this folder to
24+
/// store encrypted cached keys. May be the same as `persistent_path`.
25+
pub fn new(app_id: String, persistent_path: String, cache_path: String) -> Self {
2326
Self {
2427
url: None,
2528
app_id: CString::new(app_id).unwrap(),
26-
writable_path: CString::new(writable_path).unwrap(),
29+
persistent_path: CString::new(persistent_path).unwrap(),
30+
cache_path: CString::new(cache_path).unwrap(),
2731
sdk_type: None,
2832
}
2933
}

tests/identity/test_app.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ impl TestApp {
3131
}
3232

3333
pub fn make_options(&self) -> Options {
34-
Options::new(self.id().to_owned(), ":memory:".to_owned())
35-
.with_url(self.config.api_url.clone())
36-
.with_sdk_type("sdk-rust-test".to_string())
34+
Options::new(
35+
self.id().to_owned(),
36+
":memory:".to_owned(),
37+
":memory:".to_string(),
38+
)
39+
.with_url(self.config.api_url.clone())
40+
.with_sdk_type("sdk-rust-test".to_string())
3741
}
3842

3943
async fn new() -> Self {

tests/tanker_tests.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,25 @@ fn core_native_version() {
1616
#[tokio::test(flavor = "multi_thread")]
1717
async fn tanker_create() -> Result<(), Error> {
1818
let app = TestApp::get().await;
19-
let opts = Options::new(app.id().to_owned(), ":memory:".to_string())
20-
.with_sdk_type("sdk-rust-test".to_string());
19+
let opts = Options::new(
20+
app.id().to_owned(),
21+
":memory:".to_string(),
22+
":memory:".to_string(),
23+
)
24+
.with_sdk_type("sdk-rust-test".to_string());
2125
let core = Core::new(opts).await?;
2226
drop(core);
2327
Ok(())
2428
}
2529

2630
#[tokio::test(flavor = "multi_thread")]
2731
async fn tanker_bad_create() {
28-
let opts = Options::new("bad-app-id".to_string(), ":memory:".to_string())
29-
.with_sdk_type("sdk-rust-test".to_string());
32+
let opts = Options::new(
33+
"bad-app-id".to_string(),
34+
":memory:".to_string(),
35+
":memory:".to_string(),
36+
)
37+
.with_sdk_type("sdk-rust-test".to_string());
3038
let err = Core::new(opts)
3139
.await
3240
.expect_err("The app ID should not be accepted, it's not valid base64");

0 commit comments

Comments
 (0)