mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-27 10:39:25 -04:00
chore: move CryptoStore::save_account to Store::save_account
as it can be implemented in terms of other methods already present in the `CryptoStore` trait.
This commit is contained in:
@@ -516,7 +516,6 @@ mod tests {
|
||||
let users_for_key_claim = Arc::new(DashMap::new());
|
||||
let account = ReadOnlyAccount::with_device_id(user_id, device_id);
|
||||
let store = Arc::new(CryptoStoreWrapper::new(user_id, MemoryStore::new()));
|
||||
store.save_account(account.clone()).await.unwrap();
|
||||
let identity = Arc::new(Mutex::new(PrivateCrossSigningIdentity::empty(user_id)));
|
||||
let verification = VerificationMachine::new(
|
||||
account.static_data().clone(),
|
||||
@@ -525,6 +524,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let store = Store::new(account.clone(), identity, store, verification);
|
||||
store.save_account(account.clone()).await.unwrap();
|
||||
|
||||
let account = Account { static_data: account.static_data.clone(), store: store.clone() };
|
||||
|
||||
|
||||
@@ -65,7 +65,8 @@ macro_rules! cryptostore_integration_tests {
|
||||
pub async fn get_loaded_store(name: &str) -> (ReadOnlyAccount, impl CryptoStore) {
|
||||
let store = get_store(name, None).await;
|
||||
let account = get_account();
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
(account, store)
|
||||
}
|
||||
@@ -114,7 +115,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
assert!(store.load_account().await.unwrap().is_none());
|
||||
let account = get_account();
|
||||
|
||||
store.save_account(account).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account), ..Default::default() }).await.expect("Can't save account");
|
||||
assert!(store.get_static_account().is_some());
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
let store = get_store("load_account", None).await;
|
||||
let account = get_account();
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
let loaded_account = store.load_account().await.expect("Can't load account");
|
||||
let loaded_account = loaded_account.unwrap();
|
||||
@@ -137,7 +138,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
get_store("load_account_with_passphrase", Some("secret_passphrase")).await;
|
||||
let account = get_account();
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
let loaded_account = store.load_account().await.expect("Can't load account");
|
||||
let loaded_account = loaded_account.unwrap();
|
||||
@@ -150,12 +151,12 @@ macro_rules! cryptostore_integration_tests {
|
||||
let store = get_store("save_and_share_account", None).await;
|
||||
let account = get_account();
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
account.mark_as_shared();
|
||||
account.update_uploaded_key_count(50);
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
let loaded_account = store.load_account().await.expect("Can't load account");
|
||||
let loaded_account = loaded_account.unwrap();
|
||||
@@ -168,7 +169,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
async fn load_sessions() {
|
||||
let store = get_store("load_sessions", None).await;
|
||||
let (account, session) = get_account_and_session().await;
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
let changes = Changes { sessions: vec![session.clone()], ..Default::default() };
|
||||
|
||||
@@ -192,7 +193,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
let sender_key = session.sender_key.to_base64();
|
||||
let session_id = session.session_id().to_owned();
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() }).await.expect("Can't save account");
|
||||
|
||||
let changes = Changes { sessions: vec![session.clone()], ..Default::default() };
|
||||
store.save_changes(changes).await.unwrap();
|
||||
@@ -490,7 +491,9 @@ macro_rules! cryptostore_integration_tests {
|
||||
|
||||
let account = ReadOnlyAccount::with_device_id(&user_id, device_id);
|
||||
|
||||
store.save_account(account.clone()).await.expect("Can't save account");
|
||||
store.save_changes(Changes { account: Some(account.clone()), ..Default::default() })
|
||||
.await
|
||||
.expect("Can't save account");
|
||||
|
||||
let own_identity = get_own_identity();
|
||||
|
||||
|
||||
@@ -130,10 +130,6 @@ impl CryptoStore for MemoryStore {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
async fn save_account(&self, _: ReadOnlyAccount) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_identity(&self) -> Result<Option<PrivateCrossSigningIdentity>> {
|
||||
Ok(None)
|
||||
}
|
||||
@@ -419,7 +415,7 @@ mod tests {
|
||||
let store = MemoryStore::new();
|
||||
|
||||
assert!(store.load_account().await.unwrap().is_none());
|
||||
store.save_account(account).await.unwrap();
|
||||
store.save_changes(Changes { account: Some(account), ..Default::default() }).await.unwrap();
|
||||
|
||||
store.save_sessions(vec![session.clone()]).await;
|
||||
|
||||
|
||||
@@ -609,6 +609,13 @@ impl Store {
|
||||
self.inner.store.save_changes(changes).await
|
||||
}
|
||||
|
||||
pub(crate) async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> {
|
||||
self.inner
|
||||
.store
|
||||
.save_changes(Changes { account: Some(account), ..Default::default() })
|
||||
.await
|
||||
}
|
||||
|
||||
/// Compare the given `InboundGroupSession` with an existing session we have
|
||||
/// in the store.
|
||||
///
|
||||
|
||||
@@ -43,13 +43,6 @@ pub trait CryptoStore: AsyncTraitDeps {
|
||||
/// Load an account that was previously stored.
|
||||
async fn load_account(&self) -> Result<Option<ReadOnlyAccount>, Self::Error>;
|
||||
|
||||
/// Save the given account in the store.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `account` - The account that should be stored.
|
||||
async fn save_account(&self, account: ReadOnlyAccount) -> Result<(), Self::Error>;
|
||||
|
||||
/// Try to load a private cross signing identity, if one is stored.
|
||||
async fn load_identity(&self) -> Result<Option<PrivateCrossSigningIdentity>, Self::Error>;
|
||||
|
||||
@@ -287,10 +280,6 @@ impl<T: CryptoStore> CryptoStore for EraseCryptoStoreError<T> {
|
||||
self.0.load_account().await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> {
|
||||
self.0.save_account(account).await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn load_identity(&self) -> Result<Option<PrivateCrossSigningIdentity>> {
|
||||
self.0.load_identity().await.map_err(Into::into)
|
||||
}
|
||||
|
||||
@@ -823,11 +823,6 @@ impl_crypto_store! {
|
||||
}
|
||||
}
|
||||
|
||||
async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> {
|
||||
self.save_changes(Changes { account: Some(account), ..Default::default() })
|
||||
.await
|
||||
}
|
||||
|
||||
async fn load_identity(&self) -> Result<Option<PrivateCrossSigningIdentity>> {
|
||||
if let Some(pickle) = self
|
||||
.inner
|
||||
|
||||
@@ -665,15 +665,6 @@ impl CryptoStore for SqliteCryptoStore {
|
||||
}
|
||||
}
|
||||
|
||||
async fn save_account(&self, account: ReadOnlyAccount) -> Result<()> {
|
||||
*self.static_account.write().unwrap() = Some(account.static_data().clone());
|
||||
|
||||
let pickled_account = account.pickle().await;
|
||||
let serialized_account = self.serialize_value(&pickled_account)?;
|
||||
self.acquire().await?.set_kv("account", serialized_account).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_identity(&self) -> Result<Option<PrivateCrossSigningIdentity>> {
|
||||
let conn = self.acquire().await?;
|
||||
if let Some(i) = conn.get_kv("identity").await? {
|
||||
|
||||
Reference in New Issue
Block a user