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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
use super::*;
use crate::tree::sender_ratchet::SenderRatchetConfiguration;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct MlsGroupConfig {
pub(crate) wire_format_policy: WireFormatPolicy,
pub(crate) padding_size: usize,
pub(crate) max_past_epochs: usize,
pub(crate) number_of_resumption_secrets: usize,
pub(crate) use_ratchet_tree_extension: bool,
pub(crate) required_capabilities: RequiredCapabilitiesExtension,
pub(crate) sender_ratchet_configuration: SenderRatchetConfiguration,
}
impl MlsGroupConfig {
pub fn builder() -> MlsGroupConfigBuilder {
MlsGroupConfigBuilder::new()
}
pub fn wire_format_policy(&self) -> WireFormatPolicy {
self.wire_format_policy
}
pub fn padding_size(&self) -> usize {
self.padding_size
}
pub fn max_past_epochs(&self) -> usize {
self.max_past_epochs
}
pub fn number_of_resumption_secrets(&self) -> usize {
self.number_of_resumption_secrets
}
pub fn use_ratchet_tree_extension(&self) -> bool {
self.use_ratchet_tree_extension
}
pub fn sender_ratchet_configuration(&self) -> &SenderRatchetConfiguration {
&self.sender_ratchet_configuration
}
#[cfg(any(feature = "test-utils", test))]
pub fn test_default() -> Self {
Self::builder()
.wire_format_policy(WireFormatPolicy::new(
OutgoingWireFormatPolicy::AlwaysPlaintext,
IncomingWireFormatPolicy::Mixed,
))
.build()
}
}
#[derive(Default)]
pub struct MlsGroupConfigBuilder {
config: MlsGroupConfig,
}
impl MlsGroupConfigBuilder {
pub fn new() -> Self {
MlsGroupConfigBuilder {
config: MlsGroupConfig::default(),
}
}
pub fn wire_format_policy(mut self, wire_format_policy: WireFormatPolicy) -> Self {
self.config.wire_format_policy = wire_format_policy;
self
}
pub fn padding_size(mut self, padding_size: usize) -> Self {
self.config.padding_size = padding_size;
self
}
pub fn max_past_epochs(mut self, max_past_epochs: usize) -> Self {
self.config.max_past_epochs = max_past_epochs;
self
}
pub fn number_of_resumtion_secrets(mut self, number_of_resumption_secrets: usize) -> Self {
self.config.number_of_resumption_secrets = number_of_resumption_secrets;
self
}
pub fn use_ratchet_tree_extension(mut self, use_ratchet_tree_extension: bool) -> Self {
self.config.use_ratchet_tree_extension = use_ratchet_tree_extension;
self
}
pub fn sender_ratchet_configuration(
mut self,
sender_ratchet_configuration: SenderRatchetConfiguration,
) -> Self {
self.config.sender_ratchet_configuration = sender_ratchet_configuration;
self
}
pub fn build(self) -> MlsGroupConfig {
self.config
}
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum IncomingWireFormatPolicy {
AlwaysCiphertext,
AlwaysPlaintext,
Mixed,
}
impl IncomingWireFormatPolicy {
pub(crate) fn is_compatible_with(&self, wire_format: WireFormat) -> bool {
match self {
IncomingWireFormatPolicy::AlwaysCiphertext => wire_format == WireFormat::MlsCiphertext,
IncomingWireFormatPolicy::AlwaysPlaintext => wire_format == WireFormat::MlsPlaintext,
IncomingWireFormatPolicy::Mixed => {
wire_format == WireFormat::MlsCiphertext || wire_format == WireFormat::MlsPlaintext
}
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum OutgoingWireFormatPolicy {
AlwaysCiphertext,
AlwaysPlaintext,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct WireFormatPolicy {
outgoing: OutgoingWireFormatPolicy,
incoming: IncomingWireFormatPolicy,
}
impl WireFormatPolicy {
#[cfg(any(feature = "test-utils", test))]
pub(crate) fn new(
outgoing: OutgoingWireFormatPolicy,
incoming: IncomingWireFormatPolicy,
) -> Self {
Self { outgoing, incoming }
}
pub fn outgoing(&self) -> OutgoingWireFormatPolicy {
self.outgoing
}
pub fn incoming(&self) -> IncomingWireFormatPolicy {
self.incoming
}
}
impl Default for WireFormatPolicy {
fn default() -> Self {
PURE_CIPHERTEXT_WIRE_FORMAT_POLICY
}
}
impl From<OutgoingWireFormatPolicy> for WireFormat {
fn from(outgoing: OutgoingWireFormatPolicy) -> Self {
match outgoing {
OutgoingWireFormatPolicy::AlwaysCiphertext => WireFormat::MlsCiphertext,
OutgoingWireFormatPolicy::AlwaysPlaintext => WireFormat::MlsPlaintext,
}
}
}
pub const WIRE_FORMAT_POLICIES: [WireFormatPolicy; 4] = [
PURE_PLAINTEXT_WIRE_FORMAT_POLICY,
PURE_CIPHERTEXT_WIRE_FORMAT_POLICY,
MIXED_PLAINTEXT_WIRE_FORMAT_POLICY,
MIXED_CIPHERTEXT_WIRE_FORMAT_POLICY,
];
pub const PURE_PLAINTEXT_WIRE_FORMAT_POLICY: WireFormatPolicy = WireFormatPolicy {
outgoing: OutgoingWireFormatPolicy::AlwaysPlaintext,
incoming: IncomingWireFormatPolicy::AlwaysPlaintext,
};
pub const PURE_CIPHERTEXT_WIRE_FORMAT_POLICY: WireFormatPolicy = WireFormatPolicy {
outgoing: OutgoingWireFormatPolicy::AlwaysCiphertext,
incoming: IncomingWireFormatPolicy::AlwaysCiphertext,
};
pub const MIXED_PLAINTEXT_WIRE_FORMAT_POLICY: WireFormatPolicy = WireFormatPolicy {
outgoing: OutgoingWireFormatPolicy::AlwaysPlaintext,
incoming: IncomingWireFormatPolicy::Mixed,
};
pub const MIXED_CIPHERTEXT_WIRE_FORMAT_POLICY: WireFormatPolicy = WireFormatPolicy {
outgoing: OutgoingWireFormatPolicy::AlwaysCiphertext,
incoming: IncomingWireFormatPolicy::Mixed,
};