libsignal_protocol/ratchet/
params.rs1use crate::{kem, IdentityKey, IdentityKeyPair, KeyPair, PublicKey};
7
8pub struct AliceSignalProtocolParameters {
9 our_identity_key_pair: IdentityKeyPair,
10 our_base_key_pair: KeyPair,
11
12 their_identity_key: IdentityKey,
13 their_signed_pre_key: PublicKey,
14 their_one_time_pre_key: Option<PublicKey>,
15 their_ratchet_key: PublicKey,
16 their_kyber_pre_key: Option<kem::PublicKey>,
17}
18
19impl AliceSignalProtocolParameters {
20 pub fn new(
21 our_identity_key_pair: IdentityKeyPair,
22 our_base_key_pair: KeyPair,
23 their_identity_key: IdentityKey,
24 their_signed_pre_key: PublicKey,
25 their_ratchet_key: PublicKey,
26 ) -> Self {
27 Self {
28 our_identity_key_pair,
29 our_base_key_pair,
30 their_identity_key,
31 their_signed_pre_key,
32 their_one_time_pre_key: None,
33 their_ratchet_key,
34 their_kyber_pre_key: None,
35 }
36 }
37
38 pub fn set_their_one_time_pre_key(&mut self, ec_public: PublicKey) {
39 self.their_one_time_pre_key = Some(ec_public);
40 }
41
42 pub fn with_their_one_time_pre_key(mut self, ec_public: PublicKey) -> Self {
43 self.set_their_one_time_pre_key(ec_public);
44 self
45 }
46
47 pub fn set_their_kyber_pre_key(&mut self, kyber_public: &kem::PublicKey) {
48 self.their_kyber_pre_key = Some(kyber_public.clone());
49 }
50
51 pub fn with_their_kyber_pre_key(mut self, kyber_public: &kem::PublicKey) -> Self {
52 self.set_their_kyber_pre_key(kyber_public);
53 self
54 }
55
56 #[inline]
57 pub fn our_identity_key_pair(&self) -> &IdentityKeyPair {
58 &self.our_identity_key_pair
59 }
60
61 #[inline]
62 pub fn our_base_key_pair(&self) -> &KeyPair {
63 &self.our_base_key_pair
64 }
65
66 #[inline]
67 pub fn their_identity_key(&self) -> &IdentityKey {
68 &self.their_identity_key
69 }
70
71 #[inline]
72 pub fn their_signed_pre_key(&self) -> &PublicKey {
73 &self.their_signed_pre_key
74 }
75
76 #[inline]
77 pub fn their_one_time_pre_key(&self) -> Option<&PublicKey> {
78 self.their_one_time_pre_key.as_ref()
79 }
80
81 #[inline]
82 pub fn their_kyber_pre_key(&self) -> Option<&kem::PublicKey> {
83 self.their_kyber_pre_key.as_ref()
84 }
85
86 #[inline]
87 pub fn their_ratchet_key(&self) -> &PublicKey {
88 &self.their_ratchet_key
89 }
90}
91
92pub struct BobSignalProtocolParameters<'a> {
93 our_identity_key_pair: IdentityKeyPair,
94 our_signed_pre_key_pair: KeyPair,
95 our_one_time_pre_key_pair: Option<KeyPair>,
96 our_ratchet_key_pair: KeyPair,
97 our_kyber_pre_key_pair: Option<kem::KeyPair>,
99
100 their_identity_key: IdentityKey,
101 their_base_key: PublicKey,
102 their_kyber_ciphertext: Option<&'a kem::SerializedCiphertext>,
103}
104
105impl<'a> BobSignalProtocolParameters<'a> {
106 pub fn new(
107 our_identity_key_pair: IdentityKeyPair,
108 our_signed_pre_key_pair: KeyPair,
109 our_one_time_pre_key_pair: Option<KeyPair>,
110 our_ratchet_key_pair: KeyPair,
111 our_kyber_pre_key_pair: Option<kem::KeyPair>,
112 their_identity_key: IdentityKey,
113 their_base_key: PublicKey,
114 their_kyber_ciphertext: Option<&'a kem::SerializedCiphertext>,
115 ) -> Self {
116 Self {
117 our_identity_key_pair,
118 our_signed_pre_key_pair,
119 our_one_time_pre_key_pair,
120 our_ratchet_key_pair,
121 our_kyber_pre_key_pair,
122 their_identity_key,
123 their_base_key,
124 their_kyber_ciphertext,
125 }
126 }
127
128 #[inline]
129 pub fn our_identity_key_pair(&self) -> &IdentityKeyPair {
130 &self.our_identity_key_pair
131 }
132
133 #[inline]
134 pub fn our_signed_pre_key_pair(&self) -> &KeyPair {
135 &self.our_signed_pre_key_pair
136 }
137
138 #[inline]
139 pub fn our_one_time_pre_key_pair(&self) -> Option<&KeyPair> {
140 self.our_one_time_pre_key_pair.as_ref()
141 }
142
143 #[inline]
144 pub fn our_ratchet_key_pair(&self) -> &KeyPair {
145 &self.our_ratchet_key_pair
146 }
147
148 #[inline]
149 pub fn our_kyber_pre_key_pair(&self) -> &Option<kem::KeyPair> {
150 &self.our_kyber_pre_key_pair
151 }
152
153 #[inline]
154 pub fn their_identity_key(&self) -> &IdentityKey {
155 &self.their_identity_key
156 }
157
158 #[inline]
159 pub fn their_base_key(&self) -> &PublicKey {
160 &self.their_base_key
161 }
162
163 #[inline]
164 pub fn their_kyber_ciphertext(&self) -> Option<&kem::SerializedCiphertext> {
165 self.their_kyber_ciphertext
166 }
167}