crypto: Restore the account if we're using the sqlite store.

This commit is contained in:
Damir Jelić 2020-03-18 16:05:59 +01:00
parent 4aba058695
commit 5adab040e6
2 changed files with 21 additions and 20 deletions

View file

@ -89,20 +89,21 @@ impl OlmMachine {
path: P,
passphrase: String,
) -> Result<Self> {
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),
})
}

View file

@ -19,16 +19,6 @@ pub struct SqliteStore {
pickle_passphrase: Option<Zeroizing<String>>,
}
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;