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