1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::{Key, Nonce};
use std::{fmt, cmp};
use x25519_dalek as x;
pub struct SharedSecret {
inner: x::SharedSecret
}
impl SharedSecret {
pub const LEN: usize = 32;
pub(crate) fn from_shared_secret(inner: x::SharedSecret) -> Self {
Self { inner }
}
pub fn to_key(&self, initial_nonce: Nonce) -> Key {
Key::new(self.to_bytes(), initial_nonce.into_bytes())
}
fn to_bytes(&self) -> [u8; 32] {
self.inner.to_bytes()
}
pub(crate) fn as_slice(&self) -> &[u8] {
self.inner.as_bytes()
}
}
impl fmt::Debug for SharedSecret {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("SharedSecret")
}
}
impl cmp::PartialEq for SharedSecret {
fn eq(&self, other: &SharedSecret) -> bool {
self.as_slice() == other.as_slice()
}
}
impl cmp::Eq for SharedSecret {}