diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-23 12:08:35 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-23 12:08:35 +0200 |
commit | ee3599d5507ceee23ef3382dbda9de8e73c54a00 (patch) | |
tree | d681a3f8a5a2d5e7bea779acecd1fc0798285d9e /src/wireguard/types.rs | |
parent | Work on platform specific code (Linux) (diff) | |
download | wireguard-rs-ee3599d5507ceee23ef3382dbda9de8e73c54a00.tar.xz wireguard-rs-ee3599d5507ceee23ef3382dbda9de8e73c54a00.zip |
Moved IO traits into platform module
Diffstat (limited to 'src/wireguard/types.rs')
-rw-r--r-- | src/wireguard/types.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/wireguard/types.rs b/src/wireguard/types.rs new file mode 100644 index 0000000..51898a0 --- /dev/null +++ b/src/wireguard/types.rs @@ -0,0 +1,63 @@ +use clear_on_drop::clear::Clear; +use std::time::Instant; + +#[cfg(test)] +pub fn dummy_keypair(initiator: bool) -> KeyPair { + let k1 = Key { + key: [0x53u8; 32], + id: 0x646e6573, + }; + let k2 = Key { + key: [0x52u8; 32], + id: 0x76636572, + }; + if initiator { + KeyPair { + birth: Instant::now(), + initiator: true, + send: k1, + recv: k2, + } + } else { + KeyPair { + birth: Instant::now(), + initiator: false, + send: k2, + recv: k1, + } + } +} + +#[derive(Debug, Clone)] +pub struct Key { + pub key: [u8; 32], + pub id: u32, +} + +// zero key on drop +impl Drop for Key { + fn drop(&mut self) { + self.key.clear() + } +} + +#[cfg(test)] +impl PartialEq for Key { + fn eq(&self, other: &Self) -> bool { + self.id == other.id && self.key[..] == other.key[..] + } +} + +#[derive(Debug, Clone)] +pub struct KeyPair { + pub birth: Instant, // when was the key-pair created + pub initiator: bool, // has the key-pair been confirmed? + pub send: Key, // key for outbound messages + pub recv: Key, // key for inbound messages +} + +impl KeyPair { + pub fn local_id(&self) -> u32 { + self.recv.id + } +} |