From 0baeff0e6593d6d4d14299035a7d4e76b4090631 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Tue, 8 Jul 2025 19:28:06 -0700 Subject: [PATCH] fix: simplify decrypt packet len function This has no impact on performance, just a more read-able implementation. --- protocol/src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 02b3e58..076fad2 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -442,15 +442,12 @@ impl InboundCipher { /// # Returns /// /// The length of the rest of the packet. - pub fn decrypt_packet_len(&mut self, len_bytes: [u8; 3]) -> usize { - let mut enc_content_len = [0u8; 3]; - enc_content_len.copy_from_slice(&len_bytes); - self.length_cipher.crypt(&mut enc_content_len); - let mut content_slice = [0u8; 4]; - content_slice[0..3].copy_from_slice(&enc_content_len); - let content_len = u32::from_le_bytes(content_slice); - - content_len as usize + NUM_HEADER_BYTES + NUM_TAG_BYTES + pub fn decrypt_packet_len(&mut self, mut len_bytes: [u8; NUM_LENGTH_BYTES]) -> usize { + self.length_cipher.crypt(&mut len_bytes); + + u32::from_le_bytes([len_bytes[0], len_bytes[1], len_bytes[2], 0]) as usize + + NUM_HEADER_BYTES + + NUM_TAG_BYTES } /// Calculate the required decryption buffer length from packet length.