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}
376
377/// Commit to pending proposals error
378#[derive(Error, Debug, PartialEq, Clone)]
379pub enum CommitToPendingProposalsError<StorageError> {
380    /// See [`LibraryError`] for more details.
381    #[error(transparent)]
382    LibraryError(#[from] LibraryError),
383    /// See [`CreateCommitError`] for more details.
384    #[error(transparent)]
385    CreateCommitError(#[from] CreateCommitError),
386    /// See [`CommitBuilderStageError`] for more details.
387    #[error(transparent)]
388    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
389    /// See [`MlsGroupStateError`] for more details.
390    #[error(transparent)]
391    GroupStateError(#[from] MlsGroupStateError),
392    /// Error writing to storage
393    #[error("Error writing to storage: {0}")]
394    StorageError(StorageError),
395}
396
397/// Errors that can happen when exporting a group info object.
398#[derive(Error, Debug, PartialEq, Clone)]
399pub enum ExportGroupInfoError {
400    /// See [`LibraryError`] for more details.
401    #[error(transparent)]
402    LibraryError(#[from] LibraryError),
403    /// See [`MlsGroupStateError`] for more details.
404    #[error(transparent)]
405    GroupStateError(#[from] MlsGroupStateError),
406    /// See [`InvalidExtensionError`] for more details.
407    #[error(transparent)]
408    InvalidExtensionError(#[from] InvalidExtensionError),
409}
410
411/// Export secret error
412#[cfg(feature = "extensions-draft-08")]
413#[derive(Error, Debug, PartialEq, Clone)]
414pub enum SafeExportSecretError<StorageError> {
415    /// See [`MlsGroupStateError`] for more details.
416    #[error(transparent)]
417    GroupState(#[from] MlsGroupStateError),
418    /// See [`ApplicationExportTreeError`] for more details.
419    #[error(transparent)]
420    ApplicationExportTree(#[from] ApplicationExportTreeError),
421    /// Group doesn't support application exports.
422    #[error("Group doesn't support application exports.")]
423    Unsupported,
424    /// Storage error
425    #[error("Error accessing storage: {0}")]
426    Storage(StorageError),
427}
428
429/// Export secret error
430#[cfg(feature = "extensions-draft-08")]
431#[derive(Error, Debug, PartialEq, Clone)]
432pub enum ProcessedMessageSafeExportSecretError {
433    /// See [`StagedSafeExportSecretError`] for more details.
434    #[error(transparent)]
435    SafeExportSecretError(#[from] StagedSafeExportSecretError),
436    /// Processed message is not a commit.
437    #[error("Processed message is not a commit.")]
438    NotACommit,
439}
440
441/// Export secret error
442#[cfg(feature = "extensions-draft-08")]
443#[derive(Error, Debug, PartialEq, Clone)]
444pub enum PendingSafeExportSecretError<StorageError> {
445    /// See [`StagedSafeExportSecretError`] for more details.
446    #[error(transparent)]
447    SafeExportSecretError(#[from] StagedSafeExportSecretError),
448    /// No pending commit.
449    #[error("No pending commit.")]
450    NoPendingCommit,
451    /// Storage error
452    #[error("Error accessing storage: {0}")]
453    Storage(StorageError),
454    /// Only group members can export secrets.
455    #[error("Only group members can export secrets.")]
456    NotGroupMember,
457}
458
459/// Export secret from a pending commit
460#[cfg(feature = "extensions-draft-08")]
461#[derive(Error, Debug, PartialEq, Clone)]
462pub enum StagedSafeExportSecretError {
463    /// Only group members can export secrets.
464    #[error("Only group members can export secrets.")]
465    NotGroupMember,
466    /// See [`ApplicationExportTreeError`] for more details.
467    #[error(transparent)]
468    ApplicationExportTree(#[from] ApplicationExportTreeError),
469    /// Group doesn't support application exports.
470    #[error("Group doesn't support application exports.")]
471    Unsupported,
472}
473
474/// Export secret error
475#[derive(Error, Debug, PartialEq, Clone)]
476pub enum ExportSecretError {
477    /// See [`LibraryError`] for more details.
478    #[error(transparent)]
479    LibraryError(#[from] LibraryError),
480    /// The requested key length is too long.
481    #[error("The requested key length is too long.")]
482    KeyLengthTooLong,
483    /// See [`MlsGroupStateError`] for more details.
484    #[error(transparent)]
485    GroupStateError(#[from] MlsGroupStateError),
486}
487
488/// Propose PSK error
489#[derive(Error, Debug, PartialEq, Clone)]
490pub enum ProposePskError {
491    /// See [`PskError`] for more details.
492    #[error(transparent)]
493    Psk(#[from] PskError),
494    /// See [`MlsGroupStateError`] for more details.
495    #[error(transparent)]
496    GroupStateError(#[from] MlsGroupStateError),
497    /// See [`LibraryError`] for more details.
498    #[error(transparent)]
499    LibraryError(#[from] LibraryError),
500}
501
502/// Proposal error
503#[derive(Error, Debug, PartialEq, Clone)]
504pub enum ProposalError<StorageError> {
505    /// See [`LibraryError`] for more details.
506    #[error(transparent)]
507    LibraryError(#[from] LibraryError),
508    /// See [`ProposeAddMemberError`] for more details.
509    #[error(transparent)]
510    ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
511    /// See [`CreateAddProposalError`] for more details.
512    #[error(transparent)]
513    CreateAddProposalError(#[from] CreateAddProposalError),
514    /// See [`ProposeSelfUpdateError`] for more details.
515    #[error(transparent)]
516    ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
517    /// See [`ProposeRemoveMemberError`] for more details.
518    #[error(transparent)]
519    ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
520    /// See [`MlsGroupStateError`] for more details.
521    #[error(transparent)]
522    GroupStateError(#[from] MlsGroupStateError),
523    /// See [`ValidationError`] for more details.
524    #[error(transparent)]
525    ValidationError(#[from] ValidationError),
526    /// See [`CreateGroupContextExtProposalError`] for more details.
527    #[error(transparent)]
528    CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
529    /// See [`InvalidExtensionError`]
530    #[error(transparent)]
531    InvalidExtension(#[from] InvalidExtensionError),
532    /// Error writing proposal to storage.
533    #[error("error writing proposal to storage")]
534    StorageError(StorageError),
535}
536
537/// Remove proposal error
538#[derive(Error, Debug, PartialEq, Clone)]
539pub enum RemoveProposalError<StorageError> {
540    /// Couldn't find the proposal for the given `ProposalRef`.
541    #[error("Couldn't find the proposal for the given `ProposalRef`")]
542    ProposalNotFound,
543    /// Error erasing proposal from storage.
544    #[error("error writing proposal to storage")]
545    Storage(StorageError),
546}