From a533899727e0c631fd2a1f0969120635042459ad Mon Sep 17 00:00:00 2001 From: Evin Yulo Date: Thu, 6 Oct 2022 18:19:46 +0000 Subject: [PATCH] protocol update: addresses are preceded by 1 byte length, not 4 bytes --- src/crypto.rs | 2 +- src/message.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crypto.rs b/src/crypto.rs index c4dc832..bbc4e86 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -15,7 +15,7 @@ pub fn encrypt_message( let ciphertext = seal_precomputed(&message.to_bytes(), &nonce, &shared_key); let addr_bytes = account.addr.to_bytes(); let concat = [ - (addr_bytes.len() as u32).to_be_bytes().as_ref(), + [addr_bytes.len() as u8].as_slice(), &addr_bytes, eph_pub.0.as_ref(), &nonce.0, diff --git a/src/message.rs b/src/message.rs index 5b0c602..41c002e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -42,7 +42,7 @@ impl Message { let mut result = vec![self.other_recipients.len() as u8]; for addr in &self.other_recipients { let addr_bytes = addr.to_bytes(); - result.extend((addr_bytes.len() as u32).to_be_bytes()); + result.push(addr_bytes.len() as u8); result.extend(addr_bytes); } result.extend(self.timestamp.to_be_bytes()); @@ -59,8 +59,8 @@ impl Message { bytes = &bytes[1..]; let mut other_recipients = Vec::new(); for _ in 0..num_other_recipients { - let len = u32::from_be_bytes(bytes.get(..4)?.try_into().unwrap()) as usize; - bytes = &bytes[4..]; + let len = bytes[0] as usize; + bytes = &bytes[1..]; let addr = SufecAddr::from_bytes(&bytes[..len])?; bytes = &bytes[len..]; other_recipients.push(addr); -- 2.45.2