From 97e5e1eacca683880896d698a6f7c090cfbdae02 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Fri, 26 Jul 2019 18:45:20 +0200 Subject: [PATCH] Only impl. fmt for messages in test --- src/messages.rs | 12 +++++++++--- src/noise.rs | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/messages.rs b/src/messages.rs index 04f1532..78f0838 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -1,4 +1,7 @@ +#[cfg(test)] use hex; + +#[cfg(test)] use std::fmt; use byteorder::LittleEndian; @@ -30,7 +33,8 @@ impl Default for Initiation { fn default() -> Self { Self { f_type: >::new(TYPE_INITIATION as u32), - f_sender: >::new(0), + + f_sender: >::ZERO, f_ephemeral: [0u8; SIZE_X25519_POINT], f_static: [0u8; SIZE_X25519_POINT], f_static_tag: [0u8; SIZE_TAG], @@ -41,7 +45,7 @@ impl Default for Initiation { } impl Initiation { - pub fn parse(bytes: B) -> Result, HandshakeError> { + pub fn parse(bytes: B) -> Result, HandshakeError> { let msg: LayoutVerified = LayoutVerified::new(bytes).ok_or(HandshakeError::InvalidMessageFormat)?; @@ -53,6 +57,7 @@ impl Initiation { } } +#[cfg(test)] impl fmt::Debug for Initiation { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, @@ -95,7 +100,7 @@ pub struct Response { } impl Response { - pub fn parse(bytes: B) -> Result, HandshakeError> { + pub fn parse(bytes: B) -> Result, HandshakeError> { let msg: LayoutVerified = LayoutVerified::new(bytes).ok_or(HandshakeError::InvalidMessageFormat)?; @@ -119,6 +124,7 @@ impl Default for Response { } } +#[cfg(test)] impl fmt::Debug for Response { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, diff --git a/src/noise.rs b/src/noise.rs index 1695627..08935e0 100644 --- a/src/noise.rs +++ b/src/noise.rs @@ -376,8 +376,10 @@ pub fn create_response( )) } -pub fn consume_response(device: &Device, msg: &[u8]) -> Result, HandshakeError> { - +pub fn consume_response( + device: &Device, + msg: &[u8], +) -> Result, HandshakeError> { // parse message let msg = Response::parse(msg)?;