1pub mod exchange;
6pub mod gtk;
7pub mod igtk;
8pub mod pmk;
9pub mod ptk;
10
11pub use pmk::Pmk;
12
13use mundane::bytes;
14
15pub trait Tk {
16 fn tk(&self) -> &[u8];
17
18 fn eq_tk(&self, other: &impl Tk) -> bool {
19 bytes::constant_time_eq(self.tk(), other.tk())
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27 use hex::FromHex;
28
29 #[derive(Clone)]
30 struct DummyTk {
31 tk_field: Vec<u8>,
32 }
33 impl Tk for DummyTk {
34 fn tk(&self) -> &[u8] {
35 &self.tk_field[..]
36 }
37 }
38
39 #[test]
40 fn test_eq_tk() {
41 let dummy_tk_a =
42 DummyTk { tk_field: Vec::from_hex("aaaaaaaa").expect("could not make Vec") };
43 let dummy_tk_equivalent_a =
44 DummyTk { tk_field: Vec::from_hex("aaaaaaaa").expect("could not make Vec") };
45 let dummy_tk_b =
46 DummyTk { tk_field: Vec::from_hex("bbbbbbbb").expect("could not make Vec") };
47
48 assert!(dummy_tk_a.eq_tk(&dummy_tk_equivalent_a));
49 assert!(!dummy_tk_a.eq_tk(&dummy_tk_b));
50 }
51}