From cd737ea0581cbc3a0f75eb765efe2079002c05ed Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko <33099791+osmaczko@users.noreply.github.com> Date: Tue, 10 Feb 2026 18:34:33 +0100 Subject: [PATCH] fix: make ci checks pass --- .github/workflows/ci.yml | 10 +++------- conversations/src/context.rs | 20 +++++++------------ conversations/src/conversation.rs | 7 +++++-- conversations/src/conversation/group_test.rs | 2 +- conversations/src/conversation/privatev1.rs | 2 +- conversations/src/inbox.rs | 4 ++-- .../src/inbox/{inbox.rs => handler.rs} | 11 +++++----- conversations/src/inbox/handshake.rs | 6 +++--- conversations/src/inbox/introduction.rs | 8 ++++---- conversations/src/lib.rs | 1 - conversations/src/types.rs | 2 +- crypto/src/x3dh.rs | 14 ++++++------- .../examples/double_ratchet_basic.rs | 2 +- double-ratchets/examples/out_of_order_demo.rs | 2 +- .../examples/serialization_demo.rs | 2 +- double-ratchets/examples/storage_demo.rs | 2 +- double-ratchets/src/reader.rs | 6 +++--- double-ratchets/src/state.rs | 8 ++++---- double-ratchets/src/storage/db.rs | 2 +- double-ratchets/src/storage/session.rs | 20 +++++++++---------- storage/src/sqlite.rs | 5 +---- 21 files changed, 62 insertions(+), 74 deletions(-) rename conversations/src/inbox/{inbox.rs => handler.rs} (96%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 164bf17..53bf752 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,13 +13,9 @@ jobs: test: name: Test runs-on: ubuntu-latest - strategy: - matrix: - toolchain: - - stable steps: - uses: actions/checkout@v4 - - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: rustup update stable && rustup default stable - run: cargo build --verbose - run: cargo test --verbose @@ -28,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: rustup update stable && rustup default stable - run: rustup component add clippy - run: cargo clippy --all-targets --all-features -- -D warnings @@ -37,6 +33,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} + - run: rustup update stable && rustup default stable - run: rustup component add rustfmt - run: cargo fmt --all -- --check diff --git a/conversations/src/context.rs b/conversations/src/context.rs index 49db263..6445ef6 100644 --- a/conversations/src/context.rs +++ b/conversations/src/context.rs @@ -44,7 +44,7 @@ impl Context { let remote_id = Inbox::inbox_identifier_for_key(remote_bundle.installation_key); let payload_bytes = payloads .into_iter() - .map(|p| p.to_envelope(remote_id.clone())) + .map(|p| p.into_envelope(remote_id.clone())) .collect(); let convo_id = self.add_convo(Box::new(convo)); @@ -65,16 +65,13 @@ impl Context { // Attach conversation_ids to Envelopes Ok(payloads .into_iter() - .map(|p| p.to_envelope(convo.remote_id())) + .map(|p| p.into_envelope(convo.remote_id())) .collect()) } // Decode bytes and send to protocol for processing. pub fn handle_payload(&mut self, payload: &[u8]) -> Result, ChatError> { - let env = match EnvelopeV1::decode(payload) { - Ok(v) => v, - Err(e) => return Err(e.into()), - }; + let env = EnvelopeV1::decode(payload)?; // TODO: Impl Conversation hinting let convo_id = env.conversation_hint; @@ -102,7 +99,7 @@ impl Context { convo_id: ConversationId, enc_payload: EncryptedPayload, ) -> Result, ChatError> { - let Some(convo) = self.store.get_mut(&convo_id) else { + let Some(convo) = self.store.get_mut(convo_id) else { return Err(ChatError::Protocol("convo id not found".into())); }; @@ -115,21 +112,18 @@ impl Context { } fn add_convo(&mut self, convo: Box) -> ConversationIdOwned { - let convo_id = self.store.insert_convo(convo); - - convo_id + self.store.insert_convo(convo) } // Returns a mutable reference to a Convo for a given ConvoId fn get_convo_mut(&mut self, convo_id: ConversationId) -> Result<&mut dyn Convo, ChatError> { self.store - .get_mut(&convo_id) + .get_mut(convo_id) .ok_or_else(|| ChatError::NoConvo(convo_id.into())) } } #[cfg(test)] - mod tests { use super::*; use crate::conversation::GroupTestConvo; @@ -141,7 +135,7 @@ mod tests { let new_convo = GroupTestConvo::new(); let convo_id = store.insert_convo(Box::new(new_convo)); - let convo = store.get_mut(&convo_id).ok_or_else(|| 0); + let convo = store.get_mut(&convo_id).ok_or(0); convo.unwrap(); } } diff --git a/conversations/src/conversation.rs b/conversations/src/conversation.rs index 934526e..a148c5a 100644 --- a/conversations/src/conversation.rs +++ b/conversations/src/conversation.rs @@ -9,7 +9,7 @@ pub type ConversationId<'a> = &'a str; pub type ConversationIdOwned = Arc; pub trait Id: Debug { - fn id(&self) -> ConversationId; + fn id(&self) -> ConversationId<'_>; } pub trait Convo: Id + Debug { @@ -54,14 +54,17 @@ impl ConversationStore { Some(self.conversations.get_mut(id)?.as_mut()) } + #[allow(dead_code)] pub fn conversation_ids(&self) -> Vec { self.conversations.keys().cloned().collect() } } +#[cfg(test)] mod group_test; mod privatev1; use chat_proto::logoschat::encryption::EncryptedPayload; -pub use group_test::GroupTestConvo; +#[cfg(test)] +pub(crate) use group_test::GroupTestConvo; pub use privatev1::PrivateV1Convo; diff --git a/conversations/src/conversation/group_test.rs b/conversations/src/conversation/group_test.rs index 1b67128..e77984f 100644 --- a/conversations/src/conversation/group_test.rs +++ b/conversations/src/conversation/group_test.rs @@ -14,7 +14,7 @@ impl GroupTestConvo { } impl Id for GroupTestConvo { - fn id(&self) -> ConversationId { + fn id(&self) -> ConversationId<'_> { // implementation "grouptest" } diff --git a/conversations/src/conversation/privatev1.rs b/conversations/src/conversation/privatev1.rs index b58eb69..07af790 100644 --- a/conversations/src/conversation/privatev1.rs +++ b/conversations/src/conversation/privatev1.rs @@ -101,7 +101,7 @@ impl PrivateV1Convo { } impl Id for PrivateV1Convo { - fn id(&self) -> ConversationId { + fn id(&self) -> ConversationId<'_> { // TODO: implementation "private_v1_convo_id" } diff --git a/conversations/src/inbox.rs b/conversations/src/inbox.rs index d669e0d..7415fdb 100644 --- a/conversations/src/inbox.rs +++ b/conversations/src/inbox.rs @@ -1,6 +1,6 @@ +mod handler; mod handshake; -mod inbox; mod introduction; -pub use inbox::Inbox; +pub use handler::Inbox; pub use introduction::Introduction; diff --git a/conversations/src/inbox/inbox.rs b/conversations/src/inbox/handler.rs similarity index 96% rename from conversations/src/inbox/inbox.rs rename to conversations/src/inbox/handler.rs index 3a32a62..ddfc208 100644 --- a/conversations/src/inbox/inbox.rs +++ b/conversations/src/inbox/handler.rs @@ -1,6 +1,5 @@ use blake2::{Blake2b512, Digest}; use chat_proto::logoschat::encryption::EncryptedPayload; -use hex; use prost::Message; use prost::bytes::Bytes; use rand_core::OsRng; @@ -29,7 +28,7 @@ pub struct Inbox { ephemeral_keys: HashMap, } -impl<'a> std::fmt::Debug for Inbox { +impl std::fmt::Debug for Inbox { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Inbox") .field("ident", &self.ident) @@ -61,7 +60,7 @@ impl Inbox { PrekeyBundle { identity_key: self.ident.public_key(), - signed_prekey: signed_prekey, + signed_prekey, signature: [0u8; 64], onetime_prekey: None, } @@ -83,7 +82,7 @@ impl Inbox { }; let (seed_key, ephemeral_pub) = - InboxHandshake::perform_as_initiator(&self.ident.secret(), &pkb, &mut rng); + InboxHandshake::perform_as_initiator(self.ident.secret(), &pkb, &mut rng); let mut convo = PrivateV1Convo::new_initiator(seed_key, remote_bundle.ephemeral_key); @@ -218,7 +217,7 @@ impl Inbox { fn lookup_ephemeral_key(&self, key: &str) -> Result<&StaticSecret, ChatError> { self.ephemeral_keys .get(key) - .ok_or_else(|| return ChatError::UnknownEphemeralKey()) + .ok_or(ChatError::UnknownEphemeralKey()) } pub fn inbox_identifier_for_key(pubkey: PublicKey) -> String { @@ -228,7 +227,7 @@ impl Inbox { } impl Id for Inbox { - fn id(&self) -> ConversationId { + fn id(&self) -> ConversationId<'_> { &self.local_convo_id } } diff --git a/conversations/src/inbox/handshake.rs b/conversations/src/inbox/handshake.rs index e0576f4..7a2f0c2 100644 --- a/conversations/src/inbox/handshake.rs +++ b/conversations/src/inbox/handshake.rs @@ -85,12 +85,12 @@ mod tests { let mut rng = OsRng; // Alice (initiator) generates her identity key - let alice_identity = StaticSecret::random_from_rng(&mut rng); + let alice_identity = StaticSecret::random_from_rng(rng); let alice_identity_pub = PublicKey::from(&alice_identity); // Bob (responder) generates his keys - let bob_identity = StaticSecret::random_from_rng(&mut rng); - let bob_signed_prekey = StaticSecret::random_from_rng(&mut rng); + let bob_identity = StaticSecret::random_from_rng(rng); + let bob_signed_prekey = StaticSecret::random_from_rng(rng); let bob_signed_prekey_pub = PublicKey::from(&bob_signed_prekey); // Create Bob's prekey bundle diff --git a/conversations/src/inbox/introduction.rs b/conversations/src/inbox/introduction.rs index fc686dc..1b6ed72 100644 --- a/conversations/src/inbox/introduction.rs +++ b/conversations/src/inbox/introduction.rs @@ -18,13 +18,13 @@ impl From for Introduction { } } -impl Into> for Introduction { - fn into(self) -> Vec { +impl From for Vec { + fn from(val: Introduction) -> Self { // TODO: avoid copies, via writing directly to slice let link = format!( "Bundle:{}:{}", - hex::encode(self.installation_key.as_bytes()), - hex::encode(self.ephemeral_key.as_bytes()), + hex::encode(val.installation_key.as_bytes()), + hex::encode(val.ephemeral_key.as_bytes()), ); link.into_bytes() diff --git a/conversations/src/lib.rs b/conversations/src/lib.rs index 2da1f82..8ae1d51 100644 --- a/conversations/src/lib.rs +++ b/conversations/src/lib.rs @@ -15,7 +15,6 @@ pub use api::*; mod tests { use super::*; - use std::str::FromStr; #[test] fn test_ffi() {} diff --git a/conversations/src/types.rs b/conversations/src/types.rs index fd289a5..72b7188 100644 --- a/conversations/src/types.rs +++ b/conversations/src/types.rs @@ -27,7 +27,7 @@ pub(crate) struct AddressedEncryptedPayload { impl AddressedEncryptedPayload { // Wrap in an envelope and prepare for transmission - pub fn to_envelope(self, convo_id: String) -> AddressedEnvelope { + pub fn into_envelope(self, convo_id: String) -> AddressedEnvelope { let envelope = proto::EnvelopeV1 { // TODO: conversation_id should be obscured conversation_hint: convo_id, diff --git a/crypto/src/x3dh.rs b/crypto/src/x3dh.rs index 7b869d8..e361df7 100644 --- a/crypto/src/x3dh.rs +++ b/crypto/src/x3dh.rs @@ -134,17 +134,17 @@ mod tests { let mut rng = OsRng; // Alice (initiator) generates her identity key - let alice_identity = StaticSecret::random_from_rng(&mut rng); + let alice_identity = StaticSecret::random_from_rng(rng); let alice_identity_pub = PublicKey::from(&alice_identity); // Bob (responder) generates his keys - let bob_identity = StaticSecret::random_from_rng(&mut rng); + let bob_identity = StaticSecret::random_from_rng(rng); let bob_identity_pub = PublicKey::from(&bob_identity); - let bob_signed_prekey = StaticSecret::random_from_rng(&mut rng); + let bob_signed_prekey = StaticSecret::random_from_rng(rng); let bob_signed_prekey_pub = PublicKey::from(&bob_signed_prekey); - let bob_onetime_prekey = StaticSecret::random_from_rng(&mut rng); + let bob_onetime_prekey = StaticSecret::random_from_rng(rng); let bob_onetime_prekey_pub = PublicKey::from(&bob_onetime_prekey); // Create Bob's prekey bundle (with one-time prekey) @@ -177,14 +177,14 @@ mod tests { let mut rng = OsRng; // Alice (initiator) generates her identity key - let alice_identity = StaticSecret::random_from_rng(&mut rng); + let alice_identity = StaticSecret::random_from_rng(rng); let alice_identity_pub = PublicKey::from(&alice_identity); // Bob (responder) generates his keys - let bob_identity = StaticSecret::random_from_rng(&mut rng); + let bob_identity = StaticSecret::random_from_rng(rng); let bob_identity_pub = PublicKey::from(&bob_identity); - let bob_signed_prekey = StaticSecret::random_from_rng(&mut rng); + let bob_signed_prekey = StaticSecret::random_from_rng(rng); let bob_signed_prekey_pub = PublicKey::from(&bob_signed_prekey); // Create Bob's prekey bundle (without one-time prekey) diff --git a/double-ratchets/examples/double_ratchet_basic.rs b/double-ratchets/examples/double_ratchet_basic.rs index a48fc14..45d6618 100644 --- a/double-ratchets/examples/double_ratchet_basic.rs +++ b/double-ratchets/examples/double_ratchet_basic.rs @@ -6,7 +6,7 @@ fn main() { let bob_dh = InstallationKeyPair::generate(); - let mut alice: RatchetState = RatchetState::init_sender(shared_secret, bob_dh.public().clone()); + let mut alice: RatchetState = RatchetState::init_sender(shared_secret, *bob_dh.public()); let mut bob: RatchetState = RatchetState::init_receiver(shared_secret, bob_dh); let (ciphertext, header) = alice.encrypt_message(b"Hello Bob!"); diff --git a/double-ratchets/examples/out_of_order_demo.rs b/double-ratchets/examples/out_of_order_demo.rs index e99cdfd..246fa0f 100644 --- a/double-ratchets/examples/out_of_order_demo.rs +++ b/double-ratchets/examples/out_of_order_demo.rs @@ -15,7 +15,7 @@ fn main() { let shared_secret = [0x42u8; 32]; let bob_keypair = InstallationKeyPair::generate(); - let bob_public = bob_keypair.public().clone(); + let bob_public = *bob_keypair.public(); let conv_id = "out_of_order_conv"; let encryption_key = "super-secret-key-123!"; diff --git a/double-ratchets/examples/serialization_demo.rs b/double-ratchets/examples/serialization_demo.rs index 5833f0e..6cd9b48 100644 --- a/double-ratchets/examples/serialization_demo.rs +++ b/double-ratchets/examples/serialization_demo.rs @@ -6,7 +6,7 @@ fn main() { let bob_dh = InstallationKeyPair::generate(); - let mut alice: RatchetState = RatchetState::init_sender(shared_secret, bob_dh.public().clone()); + let mut alice: RatchetState = RatchetState::init_sender(shared_secret, *bob_dh.public()); let mut bob: RatchetState = RatchetState::init_receiver(shared_secret, bob_dh); let (ciphertext, header) = alice.encrypt_message(b"Hello Bob!"); diff --git a/double-ratchets/examples/storage_demo.rs b/double-ratchets/examples/storage_demo.rs index 8202995..771c598 100644 --- a/double-ratchets/examples/storage_demo.rs +++ b/double-ratchets/examples/storage_demo.rs @@ -55,7 +55,7 @@ fn run_conversation(alice_storage: &mut RatchetStorage, bob_storage: &mut Ratche alice_storage, conv_id, shared_secret, - bob_keypair.public().clone(), + *bob_keypair.public(), ) .unwrap(); diff --git a/double-ratchets/src/reader.rs b/double-ratchets/src/reader.rs index bb4b89f..d22705d 100644 --- a/double-ratchets/src/reader.rs +++ b/double-ratchets/src/reader.rs @@ -122,9 +122,9 @@ mod tests { #[test] fn test_sequential_reads() { - let mut data = vec![0x01]; // version - data.extend_from_slice(&[0xAA; 32]); // 32-byte array - data.extend_from_slice(&[0x00, 0x00, 0x00, 0x10]); // u32 = 16 + let mut data = vec![0x01]; // version + data.extend_from_slice(&[0xAA; 32]); // 32-byte array + data.extend_from_slice(&[0x00, 0x00, 0x00, 0x10]); // u32 = 16 let mut reader = Reader::new(&data); diff --git a/double-ratchets/src/state.rs b/double-ratchets/src/state.rs index 48ad359..6e27b07 100644 --- a/double-ratchets/src/state.rs +++ b/double-ratchets/src/state.rs @@ -345,7 +345,7 @@ impl RatchetState { *chain = next_chain; let header = Header { - dh_pub: self.dh_self.public().clone(), + dh_pub: *self.dh_self.public(), msg_num: self.msg_send, prev_chain_len: self.prev_chain_len, }; @@ -481,7 +481,7 @@ mod tests { let bob_keypair = InstallationKeyPair::generate(); // Alice initializes as sender, knowing Bob's public key - let alice = RatchetState::init_sender(shared_secret, bob_keypair.public().clone()); + let alice = RatchetState::init_sender(shared_secret, *bob_keypair.public()); // Bob initializes as receiver with his private key let bob = RatchetState::init_receiver(shared_secret, bob_keypair); @@ -554,7 +554,7 @@ mod tests { bob.decrypt_message(&ct, header).unwrap(); // Bob performs DH ratchet by trying to send - let old_bob_pub = bob.dh_self.public().clone(); + let old_bob_pub = *bob.dh_self.public(); let (bob_ct, bob_header) = { let mut b = bob.clone(); b.encrypt_message(b"reply") @@ -562,7 +562,7 @@ mod tests { assert_ne!(bob_header.dh_pub, old_bob_pub); // Alice receives Bob's message with new DH pub → ratchets - let old_alice_pub = alice.dh_self.public().clone(); + let old_alice_pub = *alice.dh_self.public(); let old_root = alice.root_key; // Even if decrypt fails (wrong key), ratchet should happen diff --git a/double-ratchets/src/storage/db.rs b/double-ratchets/src/storage/db.rs index 2c216d7..43b3f4b 100644 --- a/double-ratchets/src/storage/db.rs +++ b/double-ratchets/src/storage/db.rs @@ -280,7 +280,7 @@ mod tests { fn create_test_state() -> (RatchetState, SharedSecret) { let shared_secret = [0x42u8; 32]; let bob_keypair = InstallationKeyPair::generate(); - let state = RatchetState::init_sender(shared_secret, bob_keypair.public().clone()); + let state = RatchetState::init_sender(shared_secret, *bob_keypair.public()); (state, shared_secret) } diff --git a/double-ratchets/src/storage/session.rs b/double-ratchets/src/storage/session.rs index e7ad71e..ea3cdfc 100644 --- a/double-ratchets/src/storage/session.rs +++ b/double-ratchets/src/storage/session.rs @@ -60,7 +60,7 @@ impl<'a, D: HkdfInfo + Clone> RatchetSession<'a, D> { return Err(SessionError::ConvAlreadyExists(conversation_id.to_string())); } let state = RatchetState::::init_sender(shared_secret, remote_pub); - Ok(Self::create(storage, conversation_id, state)?) + Self::create(storage, conversation_id, state) } /// Initializes a new session as a receiver and persists the initial state. @@ -75,7 +75,7 @@ impl<'a, D: HkdfInfo + Clone> RatchetSession<'a, D> { } let state = RatchetState::::init_receiver(shared_secret, dh_self); - Ok(Self::create(storage, conversation_id, state)?) + Self::create(storage, conversation_id, state) } /// Encrypts a message and persists the updated state. @@ -169,7 +169,7 @@ mod tests { let shared_secret = [0x42; 32]; let bob_keypair = InstallationKeyPair::generate(); let alice: RatchetState = - RatchetState::init_sender(shared_secret, bob_keypair.public().clone()); + RatchetState::init_sender(shared_secret, *bob_keypair.public()); // Create session { @@ -192,7 +192,7 @@ mod tests { let shared_secret = [0x42; 32]; let bob_keypair = InstallationKeyPair::generate(); let alice: RatchetState = - RatchetState::init_sender(shared_secret, bob_keypair.public().clone()); + RatchetState::init_sender(shared_secret, *bob_keypair.public()); // Create and encrypt { @@ -216,7 +216,7 @@ mod tests { let shared_secret = [0x42; 32]; let bob_keypair = InstallationKeyPair::generate(); let alice: RatchetState = - RatchetState::init_sender(shared_secret, bob_keypair.public().clone()); + RatchetState::init_sender(shared_secret, *bob_keypair.public()); let bob: RatchetState = RatchetState::init_receiver(shared_secret, bob_keypair); @@ -255,7 +255,7 @@ mod tests { let shared_secret = [0x42; 32]; let bob_keypair = InstallationKeyPair::generate(); - let bob_pub = bob_keypair.public().clone(); + let bob_pub = *bob_keypair.public(); // First call creates { @@ -263,7 +263,7 @@ mod tests { &mut storage, "conv1", shared_secret, - bob_pub.clone(), + bob_pub, ) .unwrap(); assert_eq!(session.state().msg_send, 0); @@ -290,7 +290,7 @@ mod tests { let shared_secret = [0x42; 32]; let bob_keypair = InstallationKeyPair::generate(); - let bob_pub = bob_keypair.public().clone(); + let bob_pub = *bob_keypair.public(); // First creation succeeds { @@ -298,7 +298,7 @@ mod tests { &mut storage, "conv1", shared_secret, - bob_pub.clone(), + bob_pub, ) .unwrap(); } @@ -310,7 +310,7 @@ mod tests { &mut storage, "conv1", shared_secret, - bob_pub.clone(), + bob_pub, ); assert!(matches!(result, Err(SessionError::ConvAlreadyExists(_)))); diff --git a/storage/src/sqlite.rs b/storage/src/sqlite.rs index 0ab8132..4d42e9d 100644 --- a/storage/src/sqlite.rs +++ b/storage/src/sqlite.rs @@ -56,10 +56,7 @@ impl SqliteDb { } pub fn sqlcipher(path: String, key: String) -> Result { - Self::new(StorageConfig::Encrypted { - path: path, - key: key, - }) + Self::new(StorageConfig::Encrypted { path, key }) } /// Returns a reference to the underlying connection.