openmls 0.8.1

A Rust implementation of the Messaging Layer Security (MLS) protocol, as defined in RFC 9420.
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
//! # MlsGroup errors
//!
//! This module defines the public errors that can be returned from all calls
//! to methods of [`MlsGroup`](super::MlsGroup).

// These errors are exposed through `crate::group::errors`.

use thiserror::Error;

use crate::{
    error::LibraryError,
    extensions::errors::InvalidExtensionError,
    group::{
        errors::{
            CreateAddProposalError, CreateCommitError, MergeCommitError, StageCommitError,
            ValidationError,
        },
        CommitBuilderStageError, CreateGroupContextExtProposalError,
    },
    schedule::errors::PskError,
    treesync::{
        errors::{LeafNodeValidationError, PublicTreeError},
        node::leaf_node::LeafNodeUpdateError,
    },
};

#[cfg(feature = "extensions-draft-08")]
pub use crate::schedule::application_export_tree::ApplicationExportTreeError;

#[cfg(doc)]
use crate::group::GroupId;

/// New group error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum NewGroupError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// No matching KeyPackage was found in the key store.
    #[error("No matching KeyPackage was found in the key store.")]
    NoMatchingKeyPackage,
    /// Error accessing the storage.
    #[error("Error accessing the storage.")]
    StorageError(StorageError),
    /// Unsupported proposal type in required capabilities.
    #[error("Unsupported proposal type in required capabilities.")]
    UnsupportedProposalType,
    /// Unsupported extension type in required capabilities.
    #[error("Unsupported extension type in required capabilities.")]
    UnsupportedExtensionType,
    /// Invalid extensions set in configuration
    #[error("Invalid extensions set in configuration")]
    InvalidExtensions(#[from] InvalidExtensionError),
    /// A group with the given [`GroupId`] already exists.
    #[error("A group with the given GroupId already exists.")]
    GroupAlreadyExists,
}

/// EmptyInput error
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum EmptyInputError {
    /// An empty list of KeyPackages was provided.
    #[error("An empty list of KeyPackages was provided.")]
    AddMembers,
    /// An empty list of KeyPackage references was provided.
    #[error("An empty list of KeyPackage references was provided.")]
    RemoveMembers,
}

/// Group state error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MlsGroupStateError {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// Tried to use a group after being evicted from it.
    #[error("Tried to use a group after being evicted from it.")]
    UseAfterEviction,
    /// Can't create message because a pending proposal exists.
    #[error("Can't create message because a pending proposal exists.")]
    PendingProposal,
    /// Can't execute operation because a pending commit exists.
    #[error("Can't execute operation because a pending commit exists.")]
    PendingCommit,
    /// Can't execute operation because there is no pending commit.
    #[error("Can't execute operation because there is no pending commit")]
    NoPendingCommit,
    /// Requested pending proposal hasn't been found in local pending proposals
    #[error("Requested pending proposal hasn't been found in local pending proposals.")]
    PendingProposalNotFound,
}

/// Error merging pending commit
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MergePendingCommitError<StorageError> {
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    MlsGroupStateError(#[from] MlsGroupStateError),
    /// See [`MergeCommitError`] for more details.
    #[error(transparent)]
    MergeCommitError(#[from] MergeCommitError<StorageError>),
}

/// Process message error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum PublicProcessMessageError {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// The message's wire format is incompatible with the group's wire format policy.
    #[error("The message's wire format is incompatible with the group's wire format policy.")]
    IncompatibleWireFormat,
    /// See [`ValidationError`] for more details.
    #[error(transparent)]
    ValidationError(#[from] ValidationError),
    /// See [`StageCommitError`] for more details.
    #[error(transparent)]
    InvalidCommit(#[from] StageCommitError),
    /// External application messages are not permitted.
    #[error("External application messages are not permitted.")]
    UnauthorizedExternalApplicationMessage,
    /// External commit messages are not permitted.
    #[error("Commit messages from external senders are not permitted.")]
    UnauthorizedExternalCommitMessage,
    /// The proposal is invalid for the Sender of type [External](crate::prelude::Sender::External)
    #[error("The proposal is invalid for the Sender of type External")]
    UnsupportedProposalType,
}

/// Process message error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProcessMessageError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// Error writing to storage.
    #[error("Error writing to storage: {0}")]
    StorageError(StorageError),
    /// The message's wire format is incompatible with the group's wire format policy.
    #[error("The message's wire format is incompatible with the group's wire format policy.")]
    IncompatibleWireFormat,
    /// See [`ValidationError`] for more details.
    #[error(transparent)]
    ValidationError(#[from] ValidationError),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// See [`StageCommitError`] for more details.
    #[error(transparent)]
    InvalidCommit(#[from] StageCommitError),
    /// External application messages are not permitted.
    #[error("External application messages are not permitted.")]
    UnauthorizedExternalApplicationMessage,
    /// External commit messages are not permitted.
    #[error("Commit messages from external senders are not permitted.")]
    UnauthorizedExternalCommitMessage,
    /// The proposal is invalid for the Sender of type [External](crate::prelude::Sender::External)
    #[error("The proposal is invalid for the Sender of type External")]
    UnsupportedProposalType,

    /// Use `_with_app_data_update` functions for handling AppDataUpdate proposals
    #[cfg(feature = "extensions-draft-08")]
    #[error("Use `_with_app_data_update` functions for handling AppDataUpdate proposals")]
    FoundAppDataUpdateProposal,
}

/// Create message error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateMessageError {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
}

/// Add members error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum AddMembersError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`EmptyInputError`] for more details.
    #[error(transparent)]
    EmptyInput(#[from] EmptyInputError),
    /// See [`CreateCommitError`] for more details.
    #[error(transparent)]
    CreateCommitError(#[from] CreateCommitError),
    /// See [`CommitBuilderStageError`] for more details.
    #[error(transparent)]
    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// Error writing to storage.
    #[error("Error writing to storage")]
    StorageError(StorageError),
}

/// Add members error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum SwapMembersError<StorageError> {
    /// Unable to map the key packages to the given leaf indices.
    #[error("Number of added and removed members is not the same")]
    InvalidInput,

    /// See [`EmptyInputError`] for more details.
    #[error(transparent)]
    EmptyInput(#[from] EmptyInputError),

    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),

    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),

    /// The member that should be removed can not be found.
    #[error("The member that should be removed can not be found.")]
    UnknownMember,

    /// Error writing to storage
    #[error("Error writing to storage: {0}")]
    StorageError(StorageError),

    /// See [`CommitBuilderStageError`] for more details.
    #[error(transparent)]
    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),

    /// See [`CreateCommitError`] for more details.
    #[error(transparent)]
    CreateCommitError(#[from] CreateCommitError),
}

/// Propose add members error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposeAddMemberError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// The new member does not support all required extensions.
    #[error("The new member does not support all required extensions.")]
    UnsupportedExtensions,
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// See [`LeafNodeValidationError`] for more details.
    #[error(transparent)]
    LeafNodeValidation(#[from] LeafNodeValidationError),
    /// Error writing to storage
    #[error("Error writing to storage: {0}")]
    StorageError(StorageError),
}

/// Propose remove members error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposeRemoveMemberError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// The member that should be removed can not be found.
    #[error("The member that should be removed can not be found.")]
    UnknownMember,
    /// Error writing to storage
    #[error("Error writing to storage: {0}")]
    StorageError(StorageError),
}

/// Remove members error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum RemoveMembersError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`EmptyInputError`] for more details.
    #[error(transparent)]
    EmptyInput(#[from] EmptyInputError),
    /// See [`CreateCommitError`] for more details.
    #[error(transparent)]
    CreateCommitError(#[from] CreateCommitError),
    /// See [`CommitBuilderStageError`] for more details.
    #[error(transparent)]
    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// The member that should be removed can not be found.
    #[error("The member that should be removed can not be found.")]
    UnknownMember,
    /// Error writing to storage
    #[error("Error writing to storage: {0}")]
    StorageError(StorageError),
}

/// Leave group error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum LeaveGroupError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// An error ocurred while writing to storage
    #[error("An error ocurred while writing to storage")]
    StorageError(StorageError),
    /// SelfRemove not allowed with pure ciphertext outgoing wire format policy.
    #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
    CannotSelfRemoveWithPureCiphertext,
}

/// Self update error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum SelfUpdateError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`CreateCommitError`] for more details.
    #[error(transparent)]
    CreateCommitError(#[from] CreateCommitError),
    /// See [`CommitBuilderStageError`] for more details.
    #[error(transparent)]
    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// Error accessing the storage.
    #[error("Error accessing the storage.")]
    StorageError(StorageError),
}

/// Propose self update error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposeSelfUpdateError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),

    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// Error accessing storage.
    #[error("Error accessing storage.")]
    StorageError(StorageError),
    /// See [`PublicTreeError`] for more details.
    #[error(transparent)]
    PublicTreeError(#[from] PublicTreeError),
    /// See [`LeafNodeUpdateError`] for more details.
    #[error(transparent)]
    LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
    /// The updated leaf node does not support all group context extensions.
    #[error("The updated leaf node does not support all group context extensions.")]
    UnsupportedGroupContextExtensions,
}

/// Commit to pending proposals error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CommitToPendingProposalsError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`CreateCommitError`] for more details.
    #[error(transparent)]
    CreateCommitError(#[from] CreateCommitError),
    /// See [`CommitBuilderStageError`] for more details.
    #[error(transparent)]
    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// Error writing to storage
    #[error("Error writing to storage: {0}")]
    StorageError(StorageError),
}

/// Errors that can happen when exporting a group info object.
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExportGroupInfoError {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// See [`InvalidExtensionError`] for more details.
    #[error(transparent)]
    InvalidExtensionError(#[from] InvalidExtensionError),
}

/// Export secret error
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum SafeExportSecretError<StorageError> {
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupState(#[from] MlsGroupStateError),
    /// See [`ApplicationExportTreeError`] for more details.
    #[error(transparent)]
    ApplicationExportTree(#[from] ApplicationExportTreeError),
    /// Group doesn't support application exports.
    #[error("Group doesn't support application exports.")]
    Unsupported,
    /// Storage error
    #[error("Error accessing storage: {0}")]
    Storage(StorageError),
}

/// Export secret error
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProcessedMessageSafeExportSecretError {
    /// See [`StagedSafeExportSecretError`] for more details.
    #[error(transparent)]
    SafeExportSecretError(#[from] StagedSafeExportSecretError),
    /// Processed message is not a commit.
    #[error("Processed message is not a commit.")]
    NotACommit,
}

/// Export secret error
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum PendingSafeExportSecretError<StorageError> {
    /// See [`StagedSafeExportSecretError`] for more details.
    #[error(transparent)]
    SafeExportSecretError(#[from] StagedSafeExportSecretError),
    /// No pending commit.
    #[error("No pending commit.")]
    NoPendingCommit,
    /// Storage error
    #[error("Error accessing storage: {0}")]
    Storage(StorageError),
    /// Only group members can export secrets.
    #[error("Only group members can export secrets.")]
    NotGroupMember,
}

/// Export secret from a pending commit
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum StagedSafeExportSecretError {
    /// Only group members can export secrets.
    #[error("Only group members can export secrets.")]
    NotGroupMember,
    /// See [`ApplicationExportTreeError`] for more details.
    #[error(transparent)]
    ApplicationExportTree(#[from] ApplicationExportTreeError),
    /// Group doesn't support application exports.
    #[error("Group doesn't support application exports.")]
    Unsupported,
}

/// Export secret error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExportSecretError {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// The requested key length is too long.
    #[error("The requested key length is too long.")]
    KeyLengthTooLong,
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
}

/// Propose PSK error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposePskError {
    /// See [`PskError`] for more details.
    #[error(transparent)]
    Psk(#[from] PskError),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
}

/// Proposal error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposalError<StorageError> {
    /// See [`LibraryError`] for more details.
    #[error(transparent)]
    LibraryError(#[from] LibraryError),
    /// See [`ProposeAddMemberError`] for more details.
    #[error(transparent)]
    ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
    /// See [`CreateAddProposalError`] for more details.
    #[error(transparent)]
    CreateAddProposalError(#[from] CreateAddProposalError),
    /// See [`ProposeSelfUpdateError`] for more details.
    #[error(transparent)]
    ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
    /// See [`ProposeRemoveMemberError`] for more details.
    #[error(transparent)]
    ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
    /// See [`MlsGroupStateError`] for more details.
    #[error(transparent)]
    GroupStateError(#[from] MlsGroupStateError),
    /// See [`ValidationError`] for more details.
    #[error(transparent)]
    ValidationError(#[from] ValidationError),
    /// See [`CreateGroupContextExtProposalError`] for more details.
    #[error(transparent)]
    CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
    /// See [`InvalidExtensionError`]
    #[error(transparent)]
    InvalidExtension(#[from] InvalidExtensionError),
    /// Error writing proposal to storage.
    #[error("error writing proposal to storage")]
    StorageError(StorageError),
}

/// Remove proposal error
#[derive(Error, Debug, PartialEq, Clone)]
pub enum RemoveProposalError<StorageError> {
    /// Couldn't find the proposal for the given `ProposalRef`.
    #[error("Couldn't find the proposal for the given `ProposalRef`")]
    ProposalNotFound,
    /// Error erasing proposal from storage.
    #[error("error writing proposal to storage")]
    Storage(StorageError),
}