From 1cfd5aea1aba4b01905414351df13e8f5d4dfb1c Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Tue, 30 Jul 2019 15:28:11 +0200 Subject: Move to nested handshake message structure Having the nested structure: Handshake Message: Noise part (zerocopy message) MAC footer part (zerocopy message) Greatly simplifies processing the MAC fields, since the MAC footer covers the noise part, which can be accessed as bytes using AsBytes. --- src/noise/types.rs | 81 ------------------------------------------------------ 1 file changed, 81 deletions(-) delete mode 100644 src/noise/types.rs (limited to 'src/noise/types.rs') diff --git a/src/noise/types.rs b/src/noise/types.rs deleted file mode 100644 index 0d9a5d3..0000000 --- a/src/noise/types.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::error::Error; -use std::fmt; - -use crate::types::KeyPair; - -/* Internal types for the noise IKpsk2 implementation */ - -// config error - -#[derive(Debug)] -pub struct ConfigError(String); - -impl ConfigError { - pub fn new(s: &str) -> Self { - ConfigError(s.to_string()) - } -} - -impl fmt::Display for ConfigError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "ConfigError({})", self.0) - } -} - -impl Error for ConfigError { - fn description(&self) -> &str { - &self.0 - } - - fn source(&self) -> Option<&(dyn Error + 'static)> { - None - } -} - -// handshake error - -#[derive(Debug)] -pub enum HandshakeError { - DecryptionFailure, - UnknownPublicKey, - UnknownReceiverId, - InvalidMessageFormat, - OldTimestamp, - 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"), - } - } -} - -impl Error for HandshakeError { - fn description(&self) -> &str { - "Generic Handshake Error" - } - - fn source(&self) -> Option<&(dyn Error + 'static)> { - None - } -} - -pub type Output = ( - T, // external identifier associated with peer - // (e.g. a reference or vector index) - Option>, // message to send - Option, // resulting key-pair of successful handshake -); - -// preshared key - -pub type Psk = [u8; 32]; -- cgit v1.2.3-59-g8ed1b