From 5e6570eaf6ff8098954e7f9cbe624d31a57c54d0 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Sun, 4 Feb 2024 01:45:25 +0100 Subject: [PATCH] chore: Appease clippy --- src/olm/session/mod.rs | 31 ++++++++++++++----------------- src/xeddsa/mod.rs | 4 ++-- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/olm/session/mod.rs b/src/olm/session/mod.rs index 92791708..436e86a9 100644 --- a/src/olm/session/mod.rs +++ b/src/olm/session/mod.rs @@ -312,13 +312,8 @@ impl Session { // message from the other side. Therefore we need to filter that chain // out when trying to determine whether we've ever received a message // from the other side. - let is_empty = self - .receiving_chains - .inner - .iter() - .filter(|c| !c.belongs_to(&initial_ratchet_key)) - .next() - .is_none(); + let is_empty = + self.receiving_chains.inner.iter().any(|c| !c.belongs_to(&initial_ratchet_key)); !is_empty } @@ -612,6 +607,7 @@ impl Session { impl TryFrom for Session { type Error = crate::LibolmPickleError; + #[allow(unreachable_code, clippy::diverging_sub_expression)] fn try_from(pickle: Pickle) -> Result { let mut receiving_chains = ChainStore::new(); @@ -628,13 +624,16 @@ impl Session { } } - let session_keys = SessionKeys { + let _session_keys = SessionKeys { identity_key: pickle.session_keys.identity_key, base_key: pickle.session_keys.base_key, signed_pre_key: pickle.session_keys.one_time_key, one_time_key: None, - other_identity_key: todo!("libolm session pickles don't contain this information, \ - so there's not enough information to reconstruct a `Session`"), + // TODO: Figure out what to do with libolm session pickles + other_identity_key: unimplemented!( + "libolm session pickles don't contain this information, \ + so there's not enough information to reconstruct a `Session`" + ), }; if let Some(chain) = pickle.sender_chains.first() { @@ -654,7 +653,7 @@ impl Session { DoubleRatchet::from_ratchet_and_chain_key(ratchet, chain_key); Ok(Self { - session_keys, + session_keys: _session_keys, sending_ratchet, receiving_chains, config: SessionConfig::version_1(), @@ -668,7 +667,7 @@ impl Session { ); Ok(Self { - session_keys, + session_keys: _session_keys, sending_ratchet, receiving_chains, config: SessionConfig::version_1(), @@ -794,7 +793,7 @@ mod test { bob.generate_one_time_keys(2); let mut bob_prekeys: Vec<(KeyId, Curve25519PublicKey)> = - bob.one_time_keys().iter().map(|(t1, t2)| (t1.clone(), t2.clone())).take(2).collect(); + bob.one_time_keys().iter().map(|(t1, t2)| (*t1, *t2)).take(2).collect(); let (otk_id, otk) = bob_prekeys.pop().expect("Bob should have an OTK because we just generated it"); let (skey_id, skey) = bob_prekeys @@ -817,10 +816,8 @@ mod test { let ciphertext = alice_session.encrypt_interolm(message); if let AnyMessage::Interolm(AnyInterolmMessage::PreKey(m)) = ciphertext.into() { - let InboundCreationResult { session, .. } = bob.create_inbound_session( - alice.identity_keys().curve25519, - &m.try_into().expect("We should be able to establish the session"), - )?; + let InboundCreationResult { session, .. } = + bob.create_inbound_session(alice.identity_keys().curve25519, &m.into())?; Ok((alice, bob, alice_session, session)) } else { diff --git a/src/xeddsa/mod.rs b/src/xeddsa/mod.rs index 0ce8f81d..6a8fa3e5 100644 --- a/src/xeddsa/mod.rs +++ b/src/xeddsa/mod.rs @@ -124,8 +124,8 @@ mod test { verify(key_pair.public_key().as_bytes(), corrupted_message.as_bytes(), signature) .expect_err("The signature should be invalid"); - let mut corrupted_signature = signature.clone(); - corrupted_signature.0[0] = signature.0[0] + 1; + let mut corrupted_signature = signature; + corrupted_signature.0[0] += 1; verify(key_pair.public_key().as_bytes(), message.as_bytes(), corrupted_signature) .expect_err("The signature should be invalid"); }