mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
sled: Add a method to create a StoreConfig
This commit is contained in:
@@ -11,7 +11,7 @@ required-features = ["binary-build"]
|
||||
[features]
|
||||
default = ["encryption"]
|
||||
|
||||
encryption = ["matrix-sdk-crypto"]
|
||||
encryption = ["matrix-sdk-base/encryption", "matrix-sdk-crypto"]
|
||||
binary-build = [
|
||||
"atty",
|
||||
"clap",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#[cfg(feature = "encryption")]
|
||||
use std::path::Path;
|
||||
|
||||
use matrix_sdk_base::store::StoreConfig;
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
mod cryptostore;
|
||||
mod state_store;
|
||||
@@ -26,3 +27,33 @@ pub fn open_stores_with_path(
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a [`StoreConfig`] with an opened sled [`StateStore`] that uses the
|
||||
/// given path and passphrase. If `encryption` is enabled, a [`CryptoStore`]
|
||||
/// with the same parameters is also opened.
|
||||
pub fn make_config(
|
||||
path: impl AsRef<Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<StoreConfig, anyhow::Error> {
|
||||
let mut config = StoreConfig::new();
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
{
|
||||
let (state_store, crypto_store) = open_stores_with_path(path, passphrase)?;
|
||||
config = config.state_store(state_store);
|
||||
config = config.crypto_store(crypto_store);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "encryption"))]
|
||||
{
|
||||
let state_store = if let Some(passphrase) = passphrase {
|
||||
StateStore::open_with_passphrase(path, passphrase)?
|
||||
} else {
|
||||
StateStore::open_with_path(path)?
|
||||
};
|
||||
|
||||
config = config.state_store(Box::new(state_store));
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user