diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index ba0ac116..dddf7e72 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -15,10 +15,10 @@ features = ["docs"] rustdoc-args = ["--cfg", "feature=\"docs\""] [features] -default = ["encryption", "sled_cryptostore", "messages", "native-tls"] +default = ["encryption", "sled_cryptostore", "sled_state_store", "native-tls"] -messages = ["matrix-sdk-base/messages"] encryption = ["matrix-sdk-base/encryption", "dashmap"] +sled_state_store = ["matrix-sdk-base/sled_state_store"] sled_cryptostore = ["matrix-sdk-base/sled_cryptostore"] unstable-synapse-quirks = ["matrix-sdk-base/unstable-synapse-quirks"] markdown = ["matrix-sdk-base/markdown"] @@ -26,7 +26,7 @@ native-tls = ["reqwest/native-tls"] rustls-tls = ["reqwest/rustls-tls"] socks = ["reqwest/socks"] -docs = ["encryption", "sled_cryptostore", "messages"] +docs = ["encryption", "sled_cryptostore", "sled_state_store"] [dependencies] dashmap = { version = "4.0.1", optional = true } diff --git a/matrix_sdk_base/Cargo.toml b/matrix_sdk_base/Cargo.toml index a75754d4..4c05db0c 100644 --- a/matrix_sdk_base/Cargo.toml +++ b/matrix_sdk_base/Cargo.toml @@ -16,13 +16,13 @@ rustdoc-args = ["--cfg", "feature=\"docs\""] [features] default = [] -messages = [] encryption = ["matrix-sdk-crypto"] +sled_state_store = ["sled", "pbkdf2", "hmac", "sha2", "rand", "chacha20poly1305"] sled_cryptostore = ["matrix-sdk-crypto/sled_cryptostore"] unstable-synapse-quirks = ["matrix-sdk-common/unstable-synapse-quirks"] markdown = ["matrix-sdk-common/markdown"] -docs = ["encryption", "sled_cryptostore", "messages"] +docs = ["encryption", "sled_cryptostore"] [dependencies] dashmap= "4.0.1" @@ -35,14 +35,16 @@ matrix-sdk-crypto = { version = "0.2.0", path = "../matrix_sdk_crypto", optional # Misc dependencies thiserror = "1.0.23" -sled = "0.34.6" -chacha20poly1305 = "0.7.1" -rand = "0.8.2" -zeroize = { version = "1.2.0", features = ["zeroize_derive"] } -pbkdf2 = { version = "0.6.0", default-features = false } -hmac = "0.10.1" -sha2 = "0.9.2" futures = "0.3.8" +zeroize = { version = "1.2.0", features = ["zeroize_derive"] } + +# Deps for the sled state store +sled = { version = "0.34.6", optional = true } +chacha20poly1305 = { version = "0.7.1", optional = true } +pbkdf2 = { version = "0.6.0", default-features = false, optional = true } +hmac = { version = "0.10.1", optional = true } +sha2 = { version = "0.9.2", optional = true } +rand = { version = "0.8.2", optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] version = "1.0.1" diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 8f0241eb..e2893c29 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -279,8 +279,8 @@ impl BaseClient { /// * `config` - An optional session if the user already has one from a /// previous login call. pub fn new_with_config(config: BaseClientConfig) -> Result { - #[cfg(not(target_arch = "wasm32"))] - let (store, sled_store) = if let Some(path) = &config.store_path { + #[cfg(feature = "sled_state_store")] + let stores = if let Some(path) = &config.store_path { if config.passphrase.is_some() { info!("Opening an encrypted store in path {}", path.display()); } else { @@ -290,15 +290,15 @@ impl BaseClient { } else { Store::open_temporary()? }; - #[cfg(target_arch = "wasm32")] - let store = Store::open_memory_store(); + #[cfg(not(feature = "sled_state_store"))] + let stores = Store::open_memory_store(); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(all(feature = "encryption", feature = "sled_state_store"))] let crypto_store = if config.crypto_store.is_none() { #[cfg(feature = "sled_cryptostore")] let store: Option> = Some(Box::new( matrix_sdk_crypto::store::SledStore::open_with_database( - sled_store, + stores.1, config.passphrase.as_deref().map(|p| p.as_str()), ) .map_err(OlmError::Store)?, @@ -310,9 +310,14 @@ impl BaseClient { } else { config.crypto_store }; - #[cfg(target_arch = "wasm32")] + #[cfg(all(not(feature = "sled_state_store"), feature = "encryption"))] let crypto_store = config.crypto_store; + #[cfg(feature = "sled_state_store")] + let store = stores.0; + #[cfg(not(feature = "sled_state_store"))] + let store = stores; + Ok(BaseClient { session: store.session.clone(), sync_token: store.sync_token.clone(), @@ -403,6 +408,7 @@ impl BaseClient { } #[cfg(not(feature = "sled_cryptostore"))] { + let _ = path; *olm = Some(OlmMachine::new(&session.user_id, &session.device_id)); } } else { diff --git a/matrix_sdk_base/src/store/mod.rs b/matrix_sdk_base/src/store/mod.rs index 93fae536..cb226c2e 100644 --- a/matrix_sdk_base/src/store/mod.rs +++ b/matrix_sdk_base/src/store/mod.rs @@ -25,6 +25,7 @@ use matrix_sdk_common::{ locks::RwLock, AsyncTraitDeps, }; +#[cfg(feature = "sled_state_store")] use sled::Db; use crate::{ @@ -34,15 +35,16 @@ use crate::{ }; mod memory_store; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(feature = "sled_state_store")] mod sled_store; use self::memory_store::MemoryStore; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(feature = "sled_state_store")] use self::sled_store::SledStore; #[derive(Debug, thiserror::Error)] pub enum StoreError { + #[cfg(feature = "sled_state_store")] #[error(transparent)] Sled(#[from] sled::Error), #[error(transparent)] @@ -142,6 +144,7 @@ impl Store { Self::new(inner) } + #[cfg(feature = "sled_state_store")] pub fn open_default(path: impl AsRef, passphrase: Option<&str>) -> Result<(Self, Db)> { let inner = if let Some(passphrase) = passphrase { SledStore::open_with_passphrase(path, passphrase)? @@ -152,6 +155,7 @@ impl Store { Ok((Self::new(Box::new(inner.clone())), inner.inner)) } + #[cfg(feature = "sled_state_store")] pub fn open_temporary() -> Result<(Self, Db)> { let inner = SledStore::open()?;