From 7790c3db8f3f1e8200d6e0e25c5ed1eb9d6f7dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 10 Sep 2020 16:07:28 +0200 Subject: [PATCH] crypto: Fix a bunch of clippy warnings. --- matrix_sdk_crypto/src/key_export.rs | 8 ++++---- matrix_sdk_crypto/src/machine.rs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) 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 {