From 3a5cc833d16e389253fc2b7280387e6b67ee1d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 16 Apr 2020 10:14:23 +0200 Subject: [PATCH] crypto: Simplify the session saving methods in the cyrptostore. --- src/crypto/machine.rs | 4 ++-- src/crypto/store/memorystore.rs | 6 +----- src/crypto/store/mod.rs | 1 - src/crypto/store/sqlite.rs | 10 +++------- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/crypto/machine.rs b/src/crypto/machine.rs index 703f6836..20eeac5d 100644 --- a/src/crypto/machine.rs +++ b/src/crypto/machine.rs @@ -326,7 +326,7 @@ impl OlmMachine { } }; - if let Err(e) = self.store.add_and_save_session(session).await { + if let Err(e) = self.store.save_session(session).await { error!("Failed to store newly created Olm session {}", e); continue; } @@ -703,7 +703,7 @@ impl OlmMachine { }; let plaintext = session.decrypt(message).await?; - self.store.add_and_save_session(session).await?; + self.store.save_session(session).await?; plaintext }; diff --git a/src/crypto/store/memorystore.rs b/src/crypto/store/memorystore.rs index 6daa1dba..7536597c 100644 --- a/src/crypto/store/memorystore.rs +++ b/src/crypto/store/memorystore.rs @@ -52,11 +52,7 @@ impl CryptoStore for MemoryStore { Ok(()) } - async fn save_session(&mut self, _: Session) -> Result<()> { - Ok(()) - } - - async fn add_and_save_session(&mut self, session: Session) -> Result<()> { + async fn save_session(&mut self, session: Session) -> Result<()> { self.sessions.add(session).await; Ok(()) } diff --git a/src/crypto/store/mod.rs b/src/crypto/store/mod.rs index d059b3a7..f1ff0ffd 100644 --- a/src/crypto/store/mod.rs +++ b/src/crypto/store/mod.rs @@ -69,7 +69,6 @@ pub trait CryptoStore: Debug + Send + Sync { async fn save_account(&mut self, account: Account) -> Result<()>; async fn save_session(&mut self, session: Session) -> Result<()>; - async fn add_and_save_session(&mut self, session: Session) -> Result<()>; async fn get_sessions(&mut self, sender_key: &str) -> Result>>>>; async fn save_inbound_group_session(&mut self, session: InboundGroupSession) -> Result; diff --git a/src/crypto/store/sqlite.rs b/src/crypto/store/sqlite.rs index 99a859f4..98846790 100644 --- a/src/crypto/store/sqlite.rs +++ b/src/crypto/store/sqlite.rs @@ -323,6 +323,8 @@ impl CryptoStore for SqliteStore { } async fn save_session(&mut self, session: Session) -> Result<()> { + self.sessions.add(session.clone()).await; + let account_id = self.account_id.ok_or(CryptoStoreError::AccountUnset)?; let session_id = session.session_id(); @@ -349,12 +351,6 @@ impl CryptoStore for SqliteStore { Ok(()) } - async fn add_and_save_session(&mut self, session: Session) -> Result<()> { - self.sessions.add(session.clone()).await; - self.save_session(session).await?; - Ok(()) - } - async fn get_sessions(&mut self, sender_key: &str) -> Result>>>> { Ok(self.get_sessions_for(sender_key).await?) } @@ -599,7 +595,7 @@ mod test { .save_account(account.clone()) .await .expect("Can't save account"); - store.add_and_save_session(session).await.unwrap(); + store.save_session(session).await.unwrap(); let sessions = store.get_sessions(&sender_key).await.unwrap().unwrap(); let sessions_lock = sessions.lock().await;