crypto: Simplify the session saving methods in the cyrptostore.
parent
514ced1243
commit
3a5cc833d1
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue