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