diff options
author | 2019-07-25 22:04:35 +0200 | |
---|---|---|
committer | 2019-07-25 22:04:35 +0200 | |
commit | 43b56dfb58b780fef6bccf7e77cd3d2458a94582 (patch) | |
tree | 66caaf094a3595dabfb27e479423b3180543e9fb /src/types.rs | |
parent | Fixed GenericArray version (diff) | |
download | wireguard-rs-43b56dfb58b780fef6bccf7e77cd3d2458a94582.tar.xz wireguard-rs-43b56dfb58b780fef6bccf7e77cd3d2458a94582.zip |
Formatting
Diffstat (limited to '')
-rw-r--r-- | src/types.rs | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/types.rs b/src/types.rs index 593500f..a18057f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,5 +1,5 @@ -use std::fmt; use std::error::Error; +use std::fmt; // config error @@ -7,7 +7,7 @@ use std::error::Error; pub struct ConfigError(String); impl ConfigError { - pub fn new(s : &str) -> Self { + pub fn new(s: &str) -> Self { ConfigError(s.to_string()) } } @@ -37,24 +37,20 @@ pub enum HandshakeError { UnknownReceiverId, InvalidMessageFormat, OldTimestamp, - InvalidState + InvalidState, } impl fmt::Display for HandshakeError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - HandshakeError::DecryptionFailure => - write!(f, "Failed to AEAD:OPEN"), - HandshakeError::UnknownPublicKey => - write!(f, "Unknown public key"), - HandshakeError::UnknownReceiverId => - write!(f, "Receiver id not allocated to any handshake"), - HandshakeError::InvalidMessageFormat => - write!(f, "Invalid handshake message format"), - HandshakeError::OldTimestamp => - write!(f, "Timestamp is less/equal to the newest"), - HandshakeError::InvalidState => - write!(f, "Message does not apply to handshake state") + HandshakeError::DecryptionFailure => write!(f, "Failed to AEAD:OPEN"), + HandshakeError::UnknownPublicKey => write!(f, "Unknown public key"), + HandshakeError::UnknownReceiverId => { + write!(f, "Receiver id not allocated to any handshake") + } + HandshakeError::InvalidMessageFormat => write!(f, "Invalid handshake message format"), + HandshakeError::OldTimestamp => write!(f, "Timestamp is less/equal to the newest"), + HandshakeError::InvalidState => write!(f, "Message does not apply to handshake state"), } } } @@ -73,8 +69,8 @@ impl Error for HandshakeError { #[derive(Debug)] pub struct Key { - pub key : [u8; 32], - pub id : u32 + pub key: [u8; 32], + pub id: u32, } #[cfg(test)] @@ -86,16 +82,16 @@ impl PartialEq for Key { #[derive(Debug)] pub struct KeyPair { - pub confirmed : bool, // has the key-pair been confirmed? - pub send : Key, // key for outbound messages - pub recv : Key // key for inbound messages + pub confirmed: bool, // has the key-pair been confirmed? + pub send: Key, // key for outbound messages + pub recv: Key, // key for inbound messages } pub type Output<T> = ( - T, // external identifier associated with peer - // (e.g. a reference or vector index) + T, // external identifier associated with peer + // (e.g. a reference or vector index) Option<Vec<u8>>, // message to send - Option<KeyPair> // resulting key-pair of successful handshake + Option<KeyPair>, // resulting key-pair of successful handshake ); // preshared key |