mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-25 01:02:20 -04:00
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:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user