crypto: Restore the account if we're using the sqlite store.
This commit is contained in:
parent
4aba058695
commit
5adab040e6
2 changed files with 21 additions and 20 deletions
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue