diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-07-16 23:37:25 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-07-16 23:37:25 +0200 |
commit | 5a5d09bb416e06db6559d635dcbde46a52533b3b (patch) | |
tree | 7fa8a41352959f9c73b5381a845aa900b4eb3770 /src/types.rs | |
parent | Test precomputed values (diff) | |
download | wireguard-rs-5a5d09bb416e06db6559d635dcbde46a52533b3b.tar.xz wireguard-rs-5a5d09bb416e06db6559d635dcbde46a52533b3b.zip |
Create initiation message
Diffstat (limited to '')
-rw-r--r-- | src/types.rs | 84 |
1 files changed, 78 insertions, 6 deletions
diff --git a/src/types.rs b/src/types.rs index 391b029..54f4801 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,8 +1,71 @@ +use std::fmt; use std::sync::Mutex; +use std::error::Error; use x25519_dalek::PublicKey; use x25519_dalek::SharedSecret; +use generic_array::typenum::U32; +use generic_array::GenericArray; + +use crate::timestamp; + +// 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 struct HandshakeError {} + +impl HandshakeError { + pub fn new() -> Self { + HandshakeError{} + } +} + +impl fmt::Display for HandshakeError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "HandshakeError") + } +} + +impl Error for HandshakeError { + fn description(&self) -> &str { + "Generic Handshake Error" + } + + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } +} + +// types for resulting key-material + struct Key { key : [u8; 32], id : u32 @@ -19,17 +82,26 @@ pub struct Output ( Option<Vec<u8>> // message to send ); +// per-peer state machine + +pub type Psk = [u8; 32]; + pub struct Peer { // mutable state - pub m : Mutex<State>, + pub state : Mutex<State>, // constant state - pub pk : PublicKey, // public key of peer - pub ss : SharedSecret, // precomputed DH(static, static) - pub psk : [u8; 32] // psk of peer + pub pk : PublicKey, // public key of peer + pub ss : SharedSecret, // precomputed DH(static, static) + pub psk : Psk // psk of peer } pub enum State { - Reset, - InitiationSent, + Reset{ + ts : Option<timestamp::TAI64N> + }, + InitiationSent{ + hs : GenericArray<u8, U32>, + ck : GenericArray<u8, U32> + }, } |