From 6833399c41642537ece29a12a3230c3fa30a62d1 Mon Sep 17 00:00:00 2001 From: petarjuki7 Date: Mon, 11 Nov 2024 11:25:30 +0100 Subject: [PATCH] Using PrivateKey instead of SenderKey --- crates/context/src/lib.rs | 4 ++-- crates/node/src/sync.rs | 2 +- crates/node/src/sync/blobs.rs | 14 +++++--------- crates/node/src/sync/state.rs | 24 ++++++++---------------- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/crates/context/src/lib.rs b/crates/context/src/lib.rs index 443572a14..dedfb3e87 100644 --- a/crates/context/src/lib.rs +++ b/crates/context/src/lib.rs @@ -309,7 +309,7 @@ impl ContextManager { } handle.put( - &ContextIdentityKey::new(context.id, identity_secret.public_key()), //local node saving its local identity + &ContextIdentityKey::new(context.id, identity_secret.public_key()), &ContextIdentityValue { private_key: Some(*identity_secret), sender_key: Some(*self.new_private_key()), @@ -401,7 +401,7 @@ impl ContextManager { let Some(ContextIdentityValue { private_key: Some(requester_secret), - sender_key: None, + .. }) = handle.get(&ContextIdentityKey::new(context_id, inviter_id))? else { return Ok(None); diff --git a/crates/node/src/sync.rs b/crates/node/src/sync.rs index eec0f5252..1d92f9db6 100644 --- a/crates/node/src/sync.rs +++ b/crates/node/src/sync.rs @@ -57,7 +57,7 @@ async fn recv( let data = match shared_key { Some(key) => match key.decrypt(message_data, [0; 12]) { Some(data) => data, - None => bail!("Encryption failed"), + None => bail!("decryption failed"), }, None => message_data, }; diff --git a/crates/node/src/sync/blobs.rs b/crates/node/src/sync/blobs.rs index fff57a8b9..2ce868232 100644 --- a/crates/node/src/sync/blobs.rs +++ b/crates/node/src/sync/blobs.rs @@ -68,7 +68,7 @@ impl Node { let private_key = self .ctx_manager .get_private_key(context.id, our_identity)? - .ok_or_eyre("expected own identity to have sender key")?; + .ok_or_eyre("expected own identity to have private key")?; let shared_key = SharedKey::new(&private_key, &their_identity); @@ -148,16 +148,12 @@ impl Node { bail!("no identities found for context: {}", context.id); }; - let possible_sending_key = self + let private_key = self .ctx_manager - .get_sender_key(&context.id, &our_identity)?; - - let sending_key = match possible_sending_key { - Some(key) => key, - None => todo!(), - }; + .get_private_key(context.id, our_identity)? + .ok_or_eyre("expected own identity to have private key")?; - let shared_key = SharedKey::new(&sending_key, &our_identity); + let shared_key = SharedKey::new(&private_key, &our_identity); send( stream, diff --git a/crates/node/src/sync/state.rs b/crates/node/src/sync/state.rs index b73ed2d7a..388c46e7c 100644 --- a/crates/node/src/sync/state.rs +++ b/crates/node/src/sync/state.rs @@ -73,16 +73,12 @@ impl Node { let mut sqx_out = Sequencer::default(); - let possible_sending_key = self + let private_key = self .ctx_manager - .get_sender_key(&context.id, &our_identity)?; + .get_private_key(context.id, our_identity)? + .ok_or_eyre("expected own identity to have private key")?; - let sending_key = match possible_sending_key { - Some(key) => key, - None => todo!(), - }; - - let shared_key = SharedKey::new(&sending_key, &their_identity); + let shared_key = SharedKey::new(&private_key, &their_identity); send( stream, @@ -131,16 +127,12 @@ impl Node { bail!("no identities found for context: {}", context.id); }; - let possible_sending_key = self + let private_key = self .ctx_manager - .get_sender_key(&context.id, &our_identity)?; - - let sending_key = match possible_sending_key { - Some(key) => key, - None => todo!(), - }; + .get_private_key(context.id, our_identity)? + .ok_or_eyre("expected own identity to have private key")?; - let shared_key = SharedKey::new(&sending_key, &our_identity); + let shared_key = SharedKey::new(&private_key, &our_identity); send( stream,