diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-07-26 18:45:20 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-07-26 18:45:20 +0200 |
commit | 97e5e1eacca683880896d698a6f7c090cfbdae02 (patch) | |
tree | 88ea971be0a75d30cdf7db3f585b2ac1f5366dad /src | |
parent | Move parser code to zerocopy (diff) | |
download | wireguard-rs-97e5e1eacca683880896d698a6f7c090cfbdae02.tar.xz wireguard-rs-97e5e1eacca683880896d698a6f7c090cfbdae02.zip |
Only impl. fmt for messages in test
Diffstat (limited to 'src')
-rw-r--r-- | src/messages.rs | 12 | ||||
-rw-r--r-- | 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: <U32<LittleEndian>>::new(TYPE_INITIATION as u32), - f_sender: <U32<LittleEndian>>::new(0), + + f_sender: <U32<LittleEndian>>::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<B : ByteSlice>(bytes: B) -> Result<LayoutVerified<B, Self>, HandshakeError> { + pub fn parse<B: ByteSlice>(bytes: B) -> Result<LayoutVerified<B, Self>, HandshakeError> { let msg: LayoutVerified<B, Self> = 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<B : ByteSlice>(bytes: B) -> Result<LayoutVerified<B, Self>, HandshakeError> { + pub fn parse<B: ByteSlice>(bytes: B) -> Result<LayoutVerified<B, Self>, HandshakeError> { let msg: LayoutVerified<B, Self> = 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<T: Copy>( )) } -pub fn consume_response<T: Copy>(device: &Device<T>, msg: &[u8]) -> Result<Output<T>, HandshakeError> { - +pub fn consume_response<T: Copy>( + device: &Device<T>, + msg: &[u8], +) -> Result<Output<T>, HandshakeError> { // parse message let msg = Response::parse(msg)?; |