pub mod exchange;
pub mod gtk;
pub mod igtk;
pub mod ptk;
use mundane::bytes;
pub trait Tk {
fn tk(&self) -> &[u8];
fn eq_tk(&self, other: &impl Tk) -> bool {
bytes::constant_time_eq(self.tk(), other.tk())
}
}
#[cfg(test)]
mod tests {
use super::*;
use hex::FromHex;
#[derive(Clone)]
struct DummyTk {
tk_field: Vec<u8>,
}
impl Tk for DummyTk {
fn tk(&self) -> &[u8] {
&self.tk_field[..]
}
}
#[test]
fn test_eq_tk() {
let dummy_tk_a =
DummyTk { tk_field: Vec::from_hex("aaaaaaaa").expect("could not make Vec") };
let dummy_tk_equivalent_a =
DummyTk { tk_field: Vec::from_hex("aaaaaaaa").expect("could not make Vec") };
let dummy_tk_b =
DummyTk { tk_field: Vec::from_hex("bbbbbbbb").expect("could not make Vec") };
assert!(dummy_tk_a.eq_tk(&dummy_tk_equivalent_a));
assert!(!dummy_tk_a.eq_tk(&dummy_tk_b));
}
}