Only impl. fmt for messages in test

This commit is contained in:
Mathias Hall-Andersen
2019-07-26 18:45:20 +02:00
parent 5efb318171
commit 97e5e1eacc
2 changed files with 13 additions and 5 deletions

View File

@@ -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,

View File

@@ -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)?;