From 5adab040e6b71926c170e170661b3ad3c1d4ad1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 18 Mar 2020 16:05:59 +0100 Subject: [PATCH] crypto: Restore the account if we're using the sqlite store. --- src/crypto/machine.rs | 21 +++++++++++---------- src/crypto/store/sqlite.rs | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/crypto/machine.rs b/src/crypto/machine.rs index e7e2f548..c451b85f 100644 --- a/src/crypto/machine.rs +++ b/src/crypto/machine.rs @@ -89,20 +89,21 @@ impl OlmMachine { path: P, passphrase: String, ) -> Result { + let mut store = + SqliteStore::open_with_passphrase(&user_id.to_string(), device_id, path, passphrase) + .await?; + + let account = match store.load_account().await? { + Some(a) => a, + None => Account::new(), + }; + Ok(OlmMachine { user_id: user_id.clone(), device_id: device_id.to_owned(), - account: Arc::new(Mutex::new(Account::new())), + account: Arc::new(Mutex::new(account)), uploaded_signed_key_count: None, - store: Box::new( - SqliteStore::open_with_passphrase( - &user_id.to_string(), - device_id, - path, - passphrase, - ) - .await?, - ), + store: Box::new(store), }) } diff --git a/src/crypto/store/sqlite.rs b/src/crypto/store/sqlite.rs index fca1093e..c1f27259 100644 --- a/src/crypto/store/sqlite.rs +++ b/src/crypto/store/sqlite.rs @@ -19,16 +19,6 @@ pub struct SqliteStore { pickle_passphrase: Option>, } -impl std::fmt::Debug for SqliteStore { - fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> { - write!( - fmt, - "SqliteStore {{ user_id: {}, device_id: {}, path: {:?} }}", - self.user_id, self.device_id, self.path - ) - } -} - static DATABASE_NAME: &str = "matrix-sdk-crypto.db"; impl SqliteStore { @@ -166,6 +156,16 @@ impl CryptoStore for SqliteStore { } } +impl std::fmt::Debug for SqliteStore { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> StdResult<(), std::fmt::Error> { + write!( + fmt, + "SqliteStore {{ user_id: {}, device_id: {}, path: {:?} }}", + self.user_id, self.device_id, self.path + ) + } +} + #[cfg(test)] mod test { use std::sync::Arc;