fix(crypto): Make sure to sort the sessions by timestamp before encrypting

This ensures that we're using the correct Session even if our store
doesn't provide those in the correct order. The set is small anyways, so
this shouldn't have any performance impact.
This commit is contained in:
Damir Jelić
2022-04-19 13:53:28 +02:00
parent c0172c4858
commit edbf831a0f
2 changed files with 3 additions and 2 deletions

View File

@@ -525,7 +525,8 @@ impl ReadOnlyDevice {
};
let session = if let Some(s) = store.get_sessions(&sender_key.to_base64()).await? {
let sessions = s.lock().await;
let mut sessions = s.lock().await;
sessions.sort_by_key(|s| *s.last_use_time);
sessions.get(0).cloned()
} else {
None

View File

@@ -84,7 +84,7 @@ impl SessionManager {
if let Some(sessions) = sessions {
let mut sessions = sessions.lock().await;
sessions.sort_by_key(|s| s.creation_time.clone());
sessions.sort_by_key(|s| *s.creation_time);
let session = sessions.get(0);