diff --git a/matrix_sdk_crypto/src/key_export.rs b/matrix_sdk_crypto/src/key_export.rs index 0a490bc1..cc54a3cd 100644 --- a/matrix_sdk_crypto/src/key_export.rs +++ b/matrix_sdk_crypto/src/key_export.rs @@ -34,8 +34,8 @@ const MAC_SIZE: usize = 32; const KEY_SIZE: usize = 32; const VERSION: u8 = 1; -const HEADER: &'static str = "-----BEGIN MEGOLM SESSION DATA-----"; -const FOOTER: &'static str = "-----END MEGOLM SESSION DATA-----"; +const HEADER: &str = "-----BEGIN MEGOLM SESSION DATA-----"; +const FOOTER: &str = "-----END MEGOLM SESSION DATA-----"; fn decode(input: impl AsRef<[u8]>) -> Result, DecodeError> { decode_config(input, STANDARD_NO_PAD) @@ -113,7 +113,7 @@ pub fn decrypt_key_export( /// let encrypted_export = encrypt_key_export(&exported_keys, "1234", 1); /// # }); /// ``` -pub fn encrypt_key_export(keys: &Vec, passphrase: &str, rounds: u32) -> String { +pub fn encrypt_key_export(keys: &[ExportedRoomKey], passphrase: &str, rounds: u32) -> String { let mut plaintext = serde_json::to_string(keys).unwrap().into_bytes(); let ciphertext = encrypt_helper(&mut plaintext, passphrase, rounds); [HEADER.to_owned(), ciphertext, FOOTER.to_owned()].join("\n") @@ -246,7 +246,7 @@ mod test { let mut plaintext_bytes = plaintext.clone().into_bytes(); let ciphertext = encrypt_helper(&mut plaintext_bytes, "test", 1); - let decrypted = decrypt_helper(&mut ciphertext.clone(), "test").unwrap(); + let decrypted = decrypt_helper(&ciphertext, "test").unwrap(); prop_assert!(plaintext == decrypted); } diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 8a3449b4..3fe74fd8 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -1572,7 +1572,10 @@ impl OlmMachine { ) .await? { - if session.first_known_index().await < existing_session.first_known_index().await { + let first_index = session.first_known_index().await; + let existing_index = existing_session.first_known_index().await; + + if first_index < existing_index { sessions.push(session) } } else {