mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-17 04:58:41 -04:00
sled: Add method to create CryptoStore from StateStore
Allow to use the same database for both stores
This commit is contained in:
@@ -59,6 +59,9 @@ use sled::{
|
||||
use tokio::task::spawn_blocking;
|
||||
use tracing::{info, warn};
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
pub use crate::CryptoStore;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum DatabaseType {
|
||||
Unencrypted,
|
||||
@@ -377,6 +380,14 @@ impl SledStore {
|
||||
SledStore::open_helper(db, Some(path), None)
|
||||
}
|
||||
|
||||
#[cfg(feature = "encryption")]
|
||||
/// Open a `CryptoStore` that uses the same database as this store.
|
||||
///
|
||||
/// The given passphrase will be used to encrypt private data.
|
||||
pub fn get_crypto_store(&self, passphrase: Option<&str>) -> Result<CryptoStore, anyhow::Error> {
|
||||
CryptoStore::open_with_database(self.inner.clone(), passphrase)
|
||||
}
|
||||
|
||||
fn serialize_event(&self, event: &impl Serialize) -> Result<Vec<u8>, SledStoreError> {
|
||||
if let Some(key) = &*self.store_key {
|
||||
let encrypted = key.encrypt(event)?;
|
||||
|
||||
Reference in New Issue
Block a user