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