crypto: Simplify the session saving methods in the cyrptostore.

master
Damir Jelić 2020-04-16 10:14:23 +02:00
parent 514ced1243
commit 3a5cc833d1
4 changed files with 6 additions and 15 deletions

View File

@ -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); error!("Failed to store newly created Olm session {}", e);
continue; continue;
} }
@ -703,7 +703,7 @@ impl OlmMachine {
}; };
let plaintext = session.decrypt(message).await?; let plaintext = session.decrypt(message).await?;
self.store.add_and_save_session(session).await?; self.store.save_session(session).await?;
plaintext plaintext
}; };

View File

@ -52,11 +52,7 @@ impl CryptoStore for MemoryStore {
Ok(()) Ok(())
} }
async fn save_session(&mut self, _: Session) -> Result<()> { async fn save_session(&mut self, session: Session) -> Result<()> {
Ok(())
}
async fn add_and_save_session(&mut self, session: Session) -> Result<()> {
self.sessions.add(session).await; self.sessions.add(session).await;
Ok(()) Ok(())
} }

View File

@ -69,7 +69,6 @@ pub trait CryptoStore: Debug + Send + Sync {
async fn save_account(&mut self, account: Account) -> Result<()>; async fn save_account(&mut self, account: Account) -> Result<()>;
async fn save_session(&mut self, session: Session) -> 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<Option<Arc<Mutex<Vec<Session>>>>>; async fn get_sessions(&mut self, sender_key: &str) -> Result<Option<Arc<Mutex<Vec<Session>>>>>;
async fn save_inbound_group_session(&mut self, session: InboundGroupSession) -> Result<bool>; async fn save_inbound_group_session(&mut self, session: InboundGroupSession) -> Result<bool>;

View File

@ -323,6 +323,8 @@ impl CryptoStore for SqliteStore {
} }
async fn save_session(&mut self, session: Session) -> Result<()> { 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 account_id = self.account_id.ok_or(CryptoStoreError::AccountUnset)?;
let session_id = session.session_id(); let session_id = session.session_id();
@ -349,12 +351,6 @@ impl CryptoStore for SqliteStore {
Ok(()) 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<Option<Arc<Mutex<Vec<Session>>>>> { async fn get_sessions(&mut self, sender_key: &str) -> Result<Option<Arc<Mutex<Vec<Session>>>>> {
Ok(self.get_sessions_for(sender_key).await?) Ok(self.get_sessions_for(sender_key).await?)
} }
@ -599,7 +595,7 @@ mod test {
.save_account(account.clone()) .save_account(account.clone())
.await .await
.expect("Can't save account"); .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 = store.get_sessions(&sender_key).await.unwrap().unwrap();
let sessions_lock = sessions.lock().await; let sessions_lock = sessions.lock().await;