diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-13 22:26:12 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-13 22:26:12 +0200 |
commit | a08fd4002bfae92072f64f8d5e0084e6f248f139 (patch) | |
tree | a50315318549056627adb05bdd0a4f1a02f8541d /src/wireguard/types/keys.rs | |
parent | Port timer.c from WireGuard (diff) | |
download | wireguard-rs-a08fd4002bfae92072f64f8d5e0084e6f248f139.tar.xz wireguard-rs-a08fd4002bfae92072f64f8d5e0084e6f248f139.zip |
Work on Linux platform code
Diffstat (limited to 'src/wireguard/types/keys.rs')
-rw-r--r-- | src/wireguard/types/keys.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/wireguard/types/keys.rs b/src/wireguard/types/keys.rs new file mode 100644 index 0000000..282c4ae --- /dev/null +++ b/src/wireguard/types/keys.rs @@ -0,0 +1,36 @@ +use clear_on_drop::clear::Clear; +use std::time::Instant; + +#[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 + } +} |