From e3071724d7e8b2fe99f881140bbbefc3bd5da58d Mon Sep 17 00:00:00 2001 From: jbesraa Date: Wed, 19 Jun 2024 12:35:08 +0300 Subject: [PATCH] Rename `framing::EitherFrame` to `::Frame` --- protocols/v2/codec-sv2/src/decoder.rs | 13 +++++-------- protocols/v2/codec-sv2/src/encoder.rs | 4 ++-- protocols/v2/framing-sv2/src/framing.rs | 26 ++++++++++++------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/protocols/v2/codec-sv2/src/decoder.rs b/protocols/v2/codec-sv2/src/decoder.rs index 9f5f8e89a..4d1440018 100644 --- a/protocols/v2/codec-sv2/src/decoder.rs +++ b/protocols/v2/codec-sv2/src/decoder.rs @@ -12,7 +12,7 @@ use framing_sv2::framing::HandShakeFrame; #[cfg(feature = "noise_sv2")] use framing_sv2::header::{NOISE_HEADER_ENCRYPTED_SIZE, NOISE_HEADER_SIZE}; use framing_sv2::{ - framing::{EitherFrame, Sv2Frame}, + framing::{Frame, Sv2Frame}, header::Header, }; #[cfg(feature = "noise_sv2")] @@ -36,7 +36,7 @@ use crate::State; #[cfg(feature = "noise_sv2")] pub type StandardNoiseDecoder = WithNoise; -pub type StandardEitherFrame = EitherFrame::Slice>; +pub type StandardEitherFrame = Frame::Slice>; pub type StandardSv2Frame = Sv2Frame::Slice>; pub type StandardDecoder = WithoutNoise; @@ -51,7 +51,7 @@ pub struct WithNoise { #[cfg(feature = "noise_sv2")] impl<'a, T: Serialize + GetSize + Deserialize<'a>, B: IsBuffer + AeadBuffer> WithNoise { #[inline] - pub fn next_frame(&mut self, state: &mut State) -> Result> { + pub fn next_frame(&mut self, state: &mut State) -> Result> { match state { State::HandShake(_) => unreachable!(), State::NotInitialized(msg_len) => { @@ -97,10 +97,7 @@ impl<'a, T: Serialize + GetSize + Deserialize<'a>, B: IsBuffer + AeadBuffer> Wit } #[inline] - fn decode_noise_frame( - &mut self, - noise_codec: &mut NoiseCodec, - ) -> Result> { + fn decode_noise_frame(&mut self, noise_codec: &mut NoiseCodec) -> Result> { match ( IsBuffer::len(&self.noise_buffer), IsBuffer::len(&self.sv2_buffer), @@ -148,7 +145,7 @@ impl<'a, T: Serialize + GetSize + Deserialize<'a>, B: IsBuffer + AeadBuffer> Wit } } - fn while_handshaking(&mut self) -> EitherFrame { + fn while_handshaking(&mut self) -> Frame { let src = self.noise_buffer.get_data_owned().as_mut().to_vec(); // below is inffalible as noise frame length has been already checked diff --git a/protocols/v2/codec-sv2/src/encoder.rs b/protocols/v2/codec-sv2/src/encoder.rs index 39d10f00b..21618fda5 100644 --- a/protocols/v2/codec-sv2/src/encoder.rs +++ b/protocols/v2/codec-sv2/src/encoder.rs @@ -7,7 +7,7 @@ use core::convert::TryInto; use core::marker::PhantomData; use framing_sv2::framing::Sv2Frame; #[cfg(feature = "noise_sv2")] -use framing_sv2::framing::{EitherFrame, HandShakeFrame}; +use framing_sv2::framing::{Frame, HandShakeFrame}; #[allow(unused_imports)] pub use framing_sv2::header::NOISE_HEADER_ENCRYPTED_SIZE; @@ -43,7 +43,7 @@ pub struct NoiseEncoder { } #[cfg(feature = "noise_sv2")] -type Item = EitherFrame; +type Item = Frame; #[cfg(feature = "noise_sv2")] impl NoiseEncoder { diff --git a/protocols/v2/framing-sv2/src/framing.rs b/protocols/v2/framing-sv2/src/framing.rs index 3ce948594..616d53354 100644 --- a/protocols/v2/framing-sv2/src/framing.rs +++ b/protocols/v2/framing-sv2/src/framing.rs @@ -12,12 +12,12 @@ type Slice = buffer_sv2::Slice; /// A wrapper to be used in a context we need a generic reference to a frame /// but it doesn't matter which kind of frame it is (`Sv2Frame` or `HandShakeFrame`) #[derive(Debug)] -pub enum EitherFrame { +pub enum Frame { HandShake(HandShakeFrame), Sv2(Sv2Frame), } -impl + AsRef<[u8]>> EitherFrame { +impl + AsRef<[u8]>> Frame { pub fn encoded_length(&self) -> usize { match &self { Self::HandShake(frame) => frame.encoded_length(), @@ -26,13 +26,13 @@ impl + AsRef<[u8]>> EitherFrame { } } -impl From for EitherFrame { +impl From for Frame { fn from(v: HandShakeFrame) -> Self { Self::HandShake(v) } } -impl From> for EitherFrame { +impl From> for Frame { fn from(v: Sv2Frame) -> Self { Self::Sv2(v) } @@ -190,18 +190,17 @@ impl Sv2Frame { } } -impl TryFrom> for Sv2Frame { +impl TryFrom> for Sv2Frame { type Error = Error; - fn try_from(v: EitherFrame) -> Result { + fn try_from(v: Frame) -> Result { match v { - EitherFrame::Sv2(frame) => Ok(frame), - EitherFrame::HandShake(_) => Err(Error::ExpectedSv2Frame), + Frame::Sv2(frame) => Ok(frame), + Frame::HandShake(_) => Err(Error::ExpectedSv2Frame), } } } - /// Abstraction for a Noise Handshake Frame /// Contains only a `Slice` payload with a fixed length /// Only used during Noise Handshake process @@ -233,18 +232,17 @@ impl HandShakeFrame { } } -impl TryFrom> for HandShakeFrame { +impl TryFrom> for HandShakeFrame { type Error = Error; - fn try_from(v: EitherFrame) -> Result { + fn try_from(v: Frame) -> Result { match v { - EitherFrame::HandShake(frame) => Ok(frame), - EitherFrame::Sv2(_) => Err(Error::ExpectedHandshakeFrame), + Frame::HandShake(frame) => Ok(frame), + Frame::Sv2(_) => Err(Error::ExpectedHandshakeFrame), } } } - /// Returns a `HandShakeFrame` from a generic byte array #[allow(clippy::useless_conversion)] pub fn handshake_message_to_frame>(message: T) -> HandShakeFrame {