Skip to main content

openmls/group/mls_group/
errors.rs

1//! # MlsGroup errors
2//!
3//! This module defines the public errors that can be returned from all calls
4//! to methods of [`MlsGroup`](super::MlsGroup).
5
6// These errors are exposed through `crate::group::errors`.
7
8use thiserror::Error;
9
10use crate::{
11    error::LibraryError,
12    extensions::errors::InvalidExtensionError,
13    group::{
14        errors::{
15            CreateAddProposalError, CreateCommitError, MergeCommitError, StageCommitError,
16            ValidationError,
17        },
18        CommitBuilderStageError, CreateGroupContextExtProposalError,
19    },
20    schedule::errors::PskError,
21    treesync::{
22        errors::{LeafNodeValidationError, PublicTreeError},
23        node::leaf_node::LeafNodeUpdateError,
24    },
25};
26
27#[cfg(feature = "extensions-draft-08")]
28pub use crate::schedule::application_export_tree::ApplicationExportTreeError;
29
30#[cfg(doc)]
31use crate::group::GroupId;
32
33/// New group error
34#[derive(Error, Debug, PartialEq, Clone)]
35pub enum NewGroupError<StorageError> {
36    /// See [`LibraryError`] for more details.
37    #[error(transparent)]
38    LibraryError(#[from] LibraryError),
39    /// No matching KeyPackage was found in the key store.
40    #[error("No matching KeyPackage was found in the key store.")]
41    NoMatchingKeyPackage,
42    /// Error accessing the storage.
43    #[error("Error accessing the storage.")]
44    StorageError(StorageError),
45    /// Unsupported proposal type in required capabilities.
46    #[error("Unsupported proposal type in required capabilities.")]
47    UnsupportedProposalType,
48    /// Unsupported extension type in required capabilities.
49    #[error("Unsupported extension type in required capabilities.")]
50    UnsupportedExtensionType,
51    /// Invalid extensions set in configuration
52    #[error("Invalid extensions set in configuration")]
53    InvalidExtensions(#[from] InvalidExtensionError),
54    /// A group with the given [`GroupId`] already exists.
55    #[error("A group with the given GroupId already exists.")]
56    GroupAlreadyExists,
57}
58
59/// EmptyInput error
60#[derive(Error, Debug, PartialEq, Eq, Clone)]
61pub enum EmptyInputError {
62    /// An empty list of KeyPackages was provided.
63    #[error("An empty list of KeyPackages was provided.")]
64    AddMembers,
65    /// An empty list of KeyPackage references was provided.
66    #[error("An empty list of KeyPackage references was provided.")]
67    RemoveMembers,
68}
69
70/// Group state error
71#[derive(Error, Debug, PartialEq, Clone)]
72pub enum MlsGroupStateError {
73    /// See [`LibraryError`] for more details.
74    #[error(transparent)]
75    LibraryError(#[from] LibraryError),
76    /// Tried to use a group after being evicted from it.
77    #[error("Tried to use a group after being evicted from it.")]
78    UseAfterEviction,
79    /// Can't create message because a pending proposal exists.
80    #[error("Can't create message because a pending proposal exists.")]
81    PendingProposal,
82    /// Can't execute operation because a pending commit exists.
83    #[error("Can't execute operation because a pending commit exists.")]
84    PendingCommit,
85    /// Can't execute operation because there is no pending commit.
86    #[error("Can't execute operation because there is no pending commit")]
87    NoPendingCommit,
88    /// Requested pending proposal hasn't been found in local pending proposals
89    #[error("Requested pending proposal hasn't been found in local pending proposals.")]
90    PendingProposalNotFound,
91}
92
93/// Error merging pending commit
94#[derive(Error, Debug, PartialEq, Clone)]
95pub enum MergePendingCommitError<StorageError> {
96    /// See [`MlsGroupStateError`] for more details.
97    #[error(transparent)]
98    MlsGroupStateError(#[from] MlsGroupStateError),
99    /// See [`MergeCommitError`] for more details.
100    #[error(transparent)]
101    MergeCommitError(#[from] MergeCommitError<StorageError>),
102}
103
104/// Process message error
105#[derive(Error, Debug, PartialEq, Clone)]
106pub enum PublicProcessMessageError {
107    /// See [`LibraryError`] for more details.
108    #[error(transparent)]
109    LibraryError(#[from] LibraryError),
110    /// The message's wire format is incompatible with the group's wire format policy.
111    #[error("The message's wire format is incompatible with the group's wire format policy.")]
112    IncompatibleWireFormat,
113    /// See [`ValidationError`] for more details.
114    #[error(transparent)]
115    ValidationError(#[from] ValidationError),
116    /// See [`StageCommitError`] for more details.
117    #[error(transparent)]
118    InvalidCommit(#[from] StageCommitError),
119    /// External application messages are not permitted.
120    #[error("External application messages are not permitted.")]
121    UnauthorizedExternalApplicationMessage,
122    /// External commit messages are not permitted.
123    #[error("Commit messages from external senders are not permitted.")]
124    UnauthorizedExternalCommitMessage,
125    /// The proposal is invalid for the Sender of type [External](crate::prelude::Sender::External)
126    #[error("The proposal is invalid for the Sender of type External")]
127    UnsupportedProposalType,
128}
129
130/// Process message error
131#[derive(Error, Debug, PartialEq, Clone)]
132pub enum ProcessMessageError<StorageError> {
133    /// See [`LibraryError`] for more details.
134    #[error(transparent)]
135    LibraryError(#[from] LibraryError),
136    /// Error writing to storage.
137    #[error("Error writing to storage: {0}")]
138    StorageError(StorageError),
139    /// The message's wire format is incompatible with the group's wire format policy.
140    #[error("The message's wire format is incompatible with the group's wire format policy.")]
141    IncompatibleWireFormat,
142    /// See [`ValidationError`] for more details.
143    #[error(transparent)]
144    ValidationError(#[from] ValidationError),
145    /// See [`MlsGroupStateError`] for more details.
146    #[error(transparent)]
147    GroupStateError(#[from] MlsGroupStateError),
148    /// See [`StageCommitError`] for more details.
149    #[error(transparent)]
150    InvalidCommit(#[from] StageCommitError),
151    /// External application messages are not permitted.
152    #[error("External application messages are not permitted.")]
153    UnauthorizedExternalApplicationMessage,
154    /// External commit messages are not permitted.
155    #[error("Commit messages from external senders are not permitted.")]
156    UnauthorizedExternalCommitMessage,
157    /// The proposal is invalid for the Sender of type [External](crate::prelude::Sender::External)
158    #[error("The proposal is invalid for the Sender of type External")]
159    UnsupportedProposalType,
160
161    /// Use `_with_app_data_update` functions for handling AppDataUpdate proposals
162    #[cfg(feature = "extensions-draft-08")]
163    #[error("Use `_with_app_data_update` functions for handling AppDataUpdate proposals")]
164    FoundAppDataUpdateProposal,
165}
166
167/// Create message error
168#[derive(Error, Debug, PartialEq, Clone)]
169pub enum CreateMessageError {
170    /// See [`LibraryError`] for more details.
171    #[error(transparent)]
172    LibraryError(#[from] LibraryError),
173    /// See [`MlsGroupStateError`] for more details.
174    #[error(transparent)]
175    GroupStateError(#[from] MlsGroupStateError),
176}
177
178/// Add members error
179#[derive(Error, Debug, PartialEq, Clone)]
180pub enum AddMembersError<StorageError> {
181    /// See [`LibraryError`] for more details.
182    #[error(transparent)]
183    LibraryError(#[from] LibraryError),
184    /// See [`EmptyInputError`] for more details.
185    #[error(transparent)]
186    EmptyInput(#[from] EmptyInputError),
187    /// See [`CreateCommitError`] for more details.
188    #[error(transparent)]
189    CreateCommitError(#[from] CreateCommitError),
190    /// See [`CommitBuilderStageError`] for more details.
191    #[error(transparent)]
192    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
193    /// See [`MlsGroupStateError`] for more details.
194    #[error(transparent)]
195    GroupStateError(#[from] MlsGroupStateError),
196    /// Error writing to storage.
197    #[error("Error writing to storage")]
198    StorageError(StorageError),
199}
200
201/// Add members error
202#[derive(Error, Debug, PartialEq, Clone)]
203pub enum SwapMembersError<StorageError> {
204    /// Unable to map the key packages to the given leaf indices.
205    #[error("Number of added and removed members is not the same")]
206    InvalidInput,
207
208    /// See [`EmptyInputError`] for more details.
209    #[error(transparent)]
210    EmptyInput(#[from] EmptyInputError),
211
212    /// See [`MlsGroupStateError`] for more details.
213    #[error(transparent)]
214    GroupStateError(#[from] MlsGroupStateError),
215
216    /// See [`LibraryError`] for more details.
217    #[error(transparent)]
218    LibraryError(#[from] LibraryError),
219
220    /// The member that should be removed can not be found.
221    #[error("The member that should be removed can not be found.")]
222    UnknownMember,
223
224    /// Error writing to storage
225    #[error("Error writing to storage: {0}")]
226    StorageError(StorageError),
227
228    /// See [`CommitBuilderStageError`] for more details.
229    #[error(transparent)]
230    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
231
232    /// See [`CreateCommitError`] for more details.
233    #[error(transparent)]
234    CreateCommitError(#[from] CreateCommitError),
235}
236
237/// Propose add members error
238#[derive(Error, Debug, PartialEq, Clone)]
239pub enum ProposeAddMemberError<StorageError> {
240    /// See [`LibraryError`] for more details.
241    #[error(transparent)]
242    LibraryError(#[from] LibraryError),
243    /// The new member does not support all required extensions.
244    #[error("The new member does not support all required extensions.")]
245    UnsupportedExtensions,
246    /// See [`MlsGroupStateError`] for more details.
247    #[error(transparent)]
248    GroupStateError(#[from] MlsGroupStateError),
249    /// See [`LeafNodeValidationError`] for more details.
250    #[error(transparent)]
251    LeafNodeValidation(#[from] LeafNodeValidationError),
252    /// Error writing to storage
253    #[error("Error writing to storage: {0}")]
254    StorageError(StorageError),
255}
256
257/// Propose remove members error
258#[derive(Error, Debug, PartialEq, Clone)]
259pub enum ProposeRemoveMemberError<StorageError> {
260    /// See [`LibraryError`] for more details.
261    #[error(transparent)]
262    LibraryError(#[from] LibraryError),
263    /// See [`MlsGroupStateError`] for more details.
264    #[error(transparent)]
265    GroupStateError(#[from] MlsGroupStateError),
266    /// The member that should be removed can not be found.
267    #[error("The member that should be removed can not be found.")]
268    UnknownMember,
269    /// Error writing to storage
270    #[error("Error writing to storage: {0}")]
271    StorageError(StorageError),
272}
273
274/// Remove members error
275#[derive(Error, Debug, PartialEq, Clone)]
276pub enum RemoveMembersError<StorageError> {
277    /// See [`LibraryError`] for more details.
278    #[error(transparent)]
279    LibraryError(#[from] LibraryError),
280    /// See [`EmptyInputError`] for more details.
281    #[error(transparent)]
282    EmptyInput(#[from] EmptyInputError),
283    /// See [`CreateCommitError`] for more details.
284    #[error(transparent)]
285    CreateCommitError(#[from] CreateCommitError),
286    /// See [`CommitBuilderStageError`] for more details.
287    #[error(transparent)]
288    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
289    /// See [`MlsGroupStateError`] for more details.
290    #[error(transparent)]
291    GroupStateError(#[from] MlsGroupStateError),
292    /// The member that should be removed can not be found.
293    #[error("The member that should be removed can not be found.")]
294    UnknownMember,
295    /// Error writing to storage
296    #[error("Error writing to storage: {0}")]
297    StorageError(StorageError),
298}
299
300/// Leave group error
301#[derive(Error, Debug, PartialEq, Clone)]
302pub enum LeaveGroupError<StorageError> {
303    /// See [`LibraryError`] for more details.
304    #[error(transparent)]
305    LibraryError(#[from] LibraryError),
306    /// See [`MlsGroupStateError`] for more details.
307    #[error(transparent)]
308    GroupStateError(#[from] MlsGroupStateError),
309    /// An error ocurred while writing to storage
310    #[error("An error ocurred while writing to storage")]
311    StorageError(StorageError),
312    /// SelfRemove not allowed with pure ciphertext outgoing wire format policy.
313    #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
314    CannotSelfRemoveWithPureCiphertext,
315}
316
317/// Self update error
318#[derive(Error, Debug, PartialEq, Clone)]
319pub enum SelfUpdateError<StorageError> {
320    /// See [`LibraryError`] for more details.
321    #[error(transparent)]
322    LibraryError(#[from] LibraryError),
323    /// See [`CreateCommitError`] for more details.
324    #[error(transparent)]
325    CreateCommitError(#[from] CreateCommitError),
326    /// See [`CommitBuilderStageError`] for more details.
327    #[error(transparent)]
328    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
329    /// See [`MlsGroupStateError`] for more details.
330    #[error(transparent)]
331    GroupStateError(#[from] MlsGroupStateError),
332    /// Error accessing the storage.
333    #[error("Error accessing the storage.")]
334    StorageError(StorageError),
335}
336
337/// Propose self update error
338#[derive(Error, Debug, PartialEq, Clone)]
339pub enum ProposeSelfUpdateError<StorageError> {
340    /// See [`LibraryError`] for more details.
341    #[error(transparent)]
342    LibraryError(#[from] LibraryError),
343
344    /// See [`MlsGroupStateError`] for more details.
345    #[error(transparent)]
346    GroupStateError(#[from] MlsGroupStateError),
347    /// Error accessing storage.
348    #[error("Error accessing storage.")]
349    StorageError(StorageError),
350    /// See [`PublicTreeError`] for more details.
351    #[error(transparent)]
352    PublicTreeError(#[from] PublicTreeError),
353    /// See [`LeafNodeUpdateError`] for more details.
354    #[error(transparent)]
355    LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
356    /// The updated leaf node does not support all group context extensions.
357    #[error("The updated leaf node does not support all group context extensions.")]
358    UnsupportedGroupContextExtensions,
359}
360
361/// Commit to pending proposals error
362#[derive(Error, Debug, PartialEq, Clone)]
363pub enum CommitToPendingProposalsError<StorageError> {
364    /// See [`LibraryError`] for more details.
365    #[error(transparent)]
366    LibraryError(#[from] LibraryError),
367    /// See [`CreateCommitError`] for more details.
368    #[error(transparent)]
369    CreateCommitError(#[from] CreateCommitError),
370    /// See [`CommitBuilderStageError`] for more details.
371    #[error(transparent)]
372    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
373    /// See [`MlsGroupStateError`] for more details.
374    #[error(transparent)]
375    GroupStateError(#[from] MlsGroupStateError),
376    /// Error writing to storage
377    #[error("Error writing to storage: {0}")]
378    StorageError(StorageError),
379}
380
381/// Errors that can happen when exporting a group info object.
382#[derive(Error, Debug, PartialEq, Clone)]
383pub enum ExportGroupInfoError {
384    /// See [`LibraryError`] for more details.
385    #[error(transparent)]
386    LibraryError(#[from] LibraryError),
387    /// See [`MlsGroupStateError`] for more details.
388    #[error(transparent)]
389    GroupStateError(#[from] MlsGroupStateError),
390    /// See [`InvalidExtensionError`] for more details.
391    #[error(transparent)]
392    InvalidExtensionError(#[from] InvalidExtensionError),
393}
394
395/// Export secret error
396#[cfg(feature = "extensions-draft-08")]
397#[derive(Error, Debug, PartialEq, Clone)]
398pub enum SafeExportSecretError<StorageError> {
399    /// See [`MlsGroupStateError`] for more details.
400    #[error(transparent)]
401    GroupState(#[from] MlsGroupStateError),
402    /// See [`ApplicationExportTreeError`] for more details.
403    #[error(transparent)]
404    ApplicationExportTree(#[from] ApplicationExportTreeError),
405    /// Group doesn't support application exports.
406    #[error("Group doesn't support application exports.")]
407    Unsupported,
408    /// Storage error
409    #[error("Error accessing storage: {0}")]
410    Storage(StorageError),
411}
412
413/// Export secret error
414#[cfg(feature = "extensions-draft-08")]
415#[derive(Error, Debug, PartialEq, Clone)]
416pub enum ProcessedMessageSafeExportSecretError {
417    /// See [`StagedSafeExportSecretError`] for more details.
418    #[error(transparent)]
419    SafeExportSecretError(#[from] StagedSafeExportSecretError),
420    /// Processed message is not a commit.
421    #[error("Processed message is not a commit.")]
422    NotACommit,
423}
424
425/// Export secret error
426#[cfg(feature = "extensions-draft-08")]
427#[derive(Error, Debug, PartialEq, Clone)]
428pub enum PendingSafeExportSecretError<StorageError> {
429    /// See [`StagedSafeExportSecretError`] for more details.
430    #[error(transparent)]
431    SafeExportSecretError(#[from] StagedSafeExportSecretError),
432    /// No pending commit.
433    #[error("No pending commit.")]
434    NoPendingCommit,
435    /// Storage error
436    #[error("Error accessing storage: {0}")]
437    Storage(StorageError),
438    /// Only group members can export secrets.
439    #[error("Only group members can export secrets.")]
440    NotGroupMember,
441}
442
443/// Export secret from a pending commit
444#[cfg(feature = "extensions-draft-08")]
445#[derive(Error, Debug, PartialEq, Clone)]
446pub enum StagedSafeExportSecretError {
447    /// Only group members can export secrets.
448    #[error("Only group members can export secrets.")]
449    NotGroupMember,
450    /// See [`ApplicationExportTreeError`] for more details.
451    #[error(transparent)]
452    ApplicationExportTree(#[from] ApplicationExportTreeError),
453    /// Group doesn't support application exports.
454    #[error("Group doesn't support application exports.")]
455    Unsupported,
456}
457
458/// Export secret error
459#[derive(Error, Debug, PartialEq, Clone)]
460pub enum ExportSecretError {
461    /// See [`LibraryError`] for more details.
462    #[error(transparent)]
463    LibraryError(#[from] LibraryError),
464    /// The requested key length is too long.
465    #[error("The requested key length is too long.")]
466    KeyLengthTooLong,
467    /// See [`MlsGroupStateError`] for more details.
468    #[error(transparent)]
469    GroupStateError(#[from] MlsGroupStateError),
470}
471
472/// Propose PSK error
473#[derive(Error, Debug, PartialEq, Clone)]
474pub enum ProposePskError {
475    /// See [`PskError`] for more details.
476    #[error(transparent)]
477    Psk(#[from] PskError),
478    /// See [`MlsGroupStateError`] for more details.
479    #[error(transparent)]
480    GroupStateError(#[from] MlsGroupStateError),
481    /// See [`LibraryError`] for more details.
482    #[error(transparent)]
483    LibraryError(#[from] LibraryError),
484}
485
486/// Proposal error
487#[derive(Error, Debug, PartialEq, Clone)]
488pub enum ProposalError<StorageError> {
489    /// See [`LibraryError`] for more details.
490    #[error(transparent)]
491    LibraryError(#[from] LibraryError),
492    /// See [`ProposeAddMemberError`] for more details.
493    #[error(transparent)]
494    ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
495    /// See [`CreateAddProposalError`] for more details.
496    #[error(transparent)]
497    CreateAddProposalError(#[from] CreateAddProposalError),
498    /// See [`ProposeSelfUpdateError`] for more details.
499    #[error(transparent)]
500    ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
501    /// See [`ProposeRemoveMemberError`] for more details.
502    #[error(transparent)]
503    ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
504    /// See [`MlsGroupStateError`] for more details.
505    #[error(transparent)]
506    GroupStateError(#[from] MlsGroupStateError),
507    /// See [`ValidationError`] for more details.
508    #[error(transparent)]
509    ValidationError(#[from] ValidationError),
510    /// See [`CreateGroupContextExtProposalError`] for more details.
511    #[error(transparent)]
512    CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
513    /// See [`InvalidExtensionError`]
514    #[error(transparent)]
515    InvalidExtension(#[from] InvalidExtensionError),
516    /// Error writing proposal to storage.
517    #[error("error writing proposal to storage")]
518    StorageError(StorageError),
519}
520
521/// Remove proposal error
522#[derive(Error, Debug, PartialEq, Clone)]
523pub enum RemoveProposalError<StorageError> {
524    /// Couldn't find the proposal for the given `ProposalRef`.
525    #[error("Couldn't find the proposal for the given `ProposalRef`")]
526    ProposalNotFound,
527    /// Error erasing proposal from storage.
528    #[error("error writing proposal to storage")]
529    Storage(StorageError),
530}