From 4368dbd1d6a813a631301cdbfc1132bf5fb720ce Mon Sep 17 00:00:00 2001 From: jbesraa Date: Wed, 19 Jun 2024 12:26:32 +0300 Subject: [PATCH] Remove unused functions from `HandShakeFrame` --- protocols/v2/framing-sv2/src/framing.rs | 69 +------------------------ 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/protocols/v2/framing-sv2/src/framing.rs b/protocols/v2/framing-sv2/src/framing.rs index 23f3c18d0..3ce948594 100644 --- a/protocols/v2/framing-sv2/src/framing.rs +++ b/protocols/v2/framing-sv2/src/framing.rs @@ -1,14 +1,8 @@ -#![allow(dead_code)] -use crate::{ - header::{Header, NOISE_HEADER_LEN_OFFSET, NOISE_HEADER_SIZE}, - Error, -}; +use crate::{header::Header, Error}; use alloc::vec::Vec; use binary_sv2::{to_writer, GetSize, Serialize}; use core::convert::TryFrom; -const NOISE_MAX_LEN: usize = const_sv2::NOISE_FRAME_MAX_SIZE; - #[cfg(not(feature = "with_buffer_pool"))] type Slice = Vec; @@ -217,29 +211,11 @@ pub struct HandShakeFrame { } impl HandShakeFrame { - /// Put the Noise Frame payload into `dst` - #[inline] - fn serialize(mut self, dst: &mut [u8]) -> Result<(), Error> { - dst.swap_with_slice(self.payload.as_mut()); - Ok(()) - } - - /// Get the Noise Frame payload - #[inline] - fn payload(&mut self) -> &mut [u8] { - &mut self.payload[NOISE_HEADER_SIZE..] - } - /// Returns payload of `HandShakeFrame` as a `Vec` pub fn get_payload_when_handshaking(&self) -> Vec { self.payload[0..].to_vec() } - /// `HandShakeFrame` always returns `None`. - fn get_header(&self) -> Option { - None - } - /// Builds a `HandShakeFrame` from raw bytes. Nothing is assumed or checked about the correctness of the payload. pub fn from_bytes(bytes: Slice) -> Result { Ok(Self::from_bytes_unchecked(bytes)) @@ -250,54 +226,11 @@ impl HandShakeFrame { Self { payload: bytes } } - /// After parsing the expected `HandShakeFrame` size from `bytes`, this function helps to determine if this value - /// correctly representing the size of the frame. - /// - Returns `0` if the byte slice is of the expected size according to the header. - /// - Returns a negative value if the byte slice is smaller than a Noise Frame header; this value - /// represents how many bytes are missing. - /// - Returns a positive value if the byte slice is longer than expected; this value - /// indicates the surplus of bytes beyond the expected size. - #[inline] - fn size_hint(bytes: &[u8]) -> isize { - if bytes.len() < NOISE_HEADER_SIZE { - return (NOISE_HEADER_SIZE - bytes.len()) as isize; - }; - - let len_b = &bytes[NOISE_HEADER_LEN_OFFSET..NOISE_HEADER_SIZE]; - let expected_len = u16::from_le_bytes([len_b[0], len_b[1]]) as usize; - - if bytes.len() - NOISE_HEADER_SIZE == expected_len { - 0 - } else { - expected_len as isize - (bytes.len() - NOISE_HEADER_SIZE) as isize - } - } - /// Returns the size of the `HandShakeFrame` payload. #[inline] fn encoded_length(&self) -> usize { self.payload.len() } - - /// Tries to build a `HandShakeFrame` frame from a byte slice. - /// Returns a `HandShakeFrame` if the size of the payload fits in the frame, `None` otherwise. - /// This is quite inefficient, and should be used only to build `HandShakeFrames` - // TODO check if is used only to build `HandShakeFrames` - #[allow(clippy::useless_conversion)] - fn from_message( - message: Slice, - _message_type: u8, - _extension_type: u16, - _channel_msg: bool, - ) -> Option { - if message.len() <= NOISE_MAX_LEN { - Some(Self { - payload: message.into(), - }) - } else { - None - } - } } impl TryFrom> for HandShakeFrame {