mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 06:04:31 -04:00
sled: Add helper to open stores for encryption
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#[cfg(feature = "encryption")]
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
mod cryptostore;
|
||||
mod state_store;
|
||||
@@ -5,3 +8,21 @@ mod state_store;
|
||||
#[cfg(feature = "encryption")]
|
||||
pub use cryptostore::SledStore as CryptoStore;
|
||||
pub use state_store::SledStore as StateStore;
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
/// Create a [`StateStore`] and a [`CryptoStore`] that use the same database and
|
||||
/// passphrase.
|
||||
pub fn open_stores_with_path(
|
||||
path: impl AsRef<Path>,
|
||||
passphrase: Option<&str>,
|
||||
) -> Result<(Box<StateStore>, Box<CryptoStore>), anyhow::Error> {
|
||||
if let Some(passphrase) = passphrase {
|
||||
let state_store = StateStore::open_with_passphrase(path, passphrase)?;
|
||||
let crypto_store = state_store.get_crypto_store(Some(passphrase))?;
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
} else {
|
||||
let state_store = StateStore::open_with_path(path)?;
|
||||
let crypto_store = state_store.get_crypto_store(None)?;
|
||||
Ok((Box::new(state_store), Box::new(crypto_store)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user