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/// New group error
28#[derive(Error, Debug, PartialEq, Clone)]
29pub enum NewGroupError<StorageError> {
30    /// See [`LibraryError`] for more details.
31    #[error(transparent)]
32    LibraryError(#[from] LibraryError),
33    /// No matching KeyPackage was found in the key store.
34    #[error("No matching KeyPackage was found in the key store.")]
35    NoMatchingKeyPackage,
36    /// Error accessing the storage.
37    #[error("Error accessing the storage.")]
38    StorageError(StorageError),
39    /// Unsupported proposal type in required capabilities.
40    #[error("Unsupported proposal type in required capabilities.")]
41    UnsupportedProposalType,
42    /// Unsupported extension type in required capabilities.
43    #[error("Unsupported extension type in required capabilities.")]
44    UnsupportedExtensionType,
45    /// Invalid extensions set in configuration
46    #[error("Invalid extensions set in configuration")]
47    InvalidExtensions(#[from] InvalidExtensionError),
48}
49
50/// EmptyInput error
51#[derive(Error, Debug, PartialEq, Eq, Clone)]
52pub enum EmptyInputError {
53    /// An empty list of KeyPackages was provided.
54    #[error("An empty list of KeyPackages was provided.")]
55    AddMembers,
56    /// An empty list of KeyPackage references was provided.
57    #[error("An empty list of KeyPackage references was provided.")]
58    RemoveMembers,
59}
60
61/// Group state error
62#[derive(Error, Debug, PartialEq, Clone)]
63pub enum MlsGroupStateError {
64    /// See [`LibraryError`] for more details.
65    #[error(transparent)]
66    LibraryError(#[from] LibraryError),
67    /// Tried to use a group after being evicted from it.
68    #[error("Tried to use a group after being evicted from it.")]
69    UseAfterEviction,
70    /// Can't create message because a pending proposal exists.
71    #[error("Can't create message because a pending proposal exists.")]
72    PendingProposal,
73    /// Can't execute operation because a pending commit exists.
74    #[error("Can't execute operation because a pending commit exists.")]
75    PendingCommit,
76    /// Can't execute operation because there is no pending commit.
77    #[error("Can't execute operation because there is no pending commit")]
78    NoPendingCommit,
79    /// Requested pending proposal hasn't been found in local pending proposals
80    #[error("Requested pending proposal hasn't been found in local pending proposals.")]
81    PendingProposalNotFound,
82}
83
84/// Error merging pending commit
85#[derive(Error, Debug, PartialEq, Clone)]
86pub enum MergePendingCommitError<StorageError> {
87    /// See [`MlsGroupStateError`] for more details.
88    #[error(transparent)]
89    MlsGroupStateError(#[from] MlsGroupStateError),
90    /// See [`MergeCommitError`] for more details.
91    #[error(transparent)]
92    MergeCommitError(#[from] MergeCommitError<StorageError>),
93}
94
95/// Process message error
96#[derive(Error, Debug, PartialEq, Clone)]
97pub enum ProcessMessageError {
98    /// See [`LibraryError`] for more details.
99    #[error(transparent)]
100    LibraryError(#[from] LibraryError),
101    /// The message's wire format is incompatible with the group's wire format policy.
102    #[error("The message's wire format is incompatible with the group's wire format policy.")]
103    IncompatibleWireFormat,
104    /// See [`ValidationError`] for more details.
105    #[error(transparent)]
106    ValidationError(#[from] ValidationError),
107    /// See [`MlsGroupStateError`] for more details.
108    #[error(transparent)]
109    GroupStateError(#[from] MlsGroupStateError),
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/// Create message error
125#[derive(Error, Debug, PartialEq, Clone)]
126pub enum CreateMessageError {
127    /// See [`LibraryError`] for more details.
128    #[error(transparent)]
129    LibraryError(#[from] LibraryError),
130    /// See [`MlsGroupStateError`] for more details.
131    #[error(transparent)]
132    GroupStateError(#[from] MlsGroupStateError),
133}
134
135/// Add members error
136#[derive(Error, Debug, PartialEq, Clone)]
137pub enum AddMembersError<StorageError> {
138    /// See [`LibraryError`] for more details.
139    #[error(transparent)]
140    LibraryError(#[from] LibraryError),
141    /// See [`EmptyInputError`] for more details.
142    #[error(transparent)]
143    EmptyInput(#[from] EmptyInputError),
144    /// See [`CreateCommitError`] for more details.
145    #[error(transparent)]
146    CreateCommitError(#[from] CreateCommitError),
147    /// See [`CommitBuilderStageError`] for more details.
148    #[error(transparent)]
149    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
150    /// See [`MlsGroupStateError`] for more details.
151    #[error(transparent)]
152    GroupStateError(#[from] MlsGroupStateError),
153    /// Error writing to storage.
154    #[error("Error writing to storage")]
155    StorageError(StorageError),
156}
157
158/// Propose add members error
159#[derive(Error, Debug, PartialEq, Clone)]
160pub enum ProposeAddMemberError<StorageError> {
161    /// See [`LibraryError`] for more details.
162    #[error(transparent)]
163    LibraryError(#[from] LibraryError),
164    /// The new member does not support all required extensions.
165    #[error("The new member does not support all required extensions.")]
166    UnsupportedExtensions,
167    /// See [`MlsGroupStateError`] for more details.
168    #[error(transparent)]
169    GroupStateError(#[from] MlsGroupStateError),
170    /// See [`LeafNodeValidationError`] for more details.
171    #[error(transparent)]
172    LeafNodeValidation(#[from] LeafNodeValidationError),
173    /// Error writing to storage
174    #[error("Error writing to storage: {0}")]
175    StorageError(StorageError),
176}
177
178/// Propose remove members error
179#[derive(Error, Debug, PartialEq, Clone)]
180pub enum ProposeRemoveMemberError<StorageError> {
181    /// See [`LibraryError`] for more details.
182    #[error(transparent)]
183    LibraryError(#[from] LibraryError),
184    /// See [`MlsGroupStateError`] for more details.
185    #[error(transparent)]
186    GroupStateError(#[from] MlsGroupStateError),
187    /// The member that should be removed can not be found.
188    #[error("The member that should be removed can not be found.")]
189    UnknownMember,
190    /// Error writing to storage
191    #[error("Error writing to storage: {0}")]
192    StorageError(StorageError),
193}
194
195/// Remove members error
196#[derive(Error, Debug, PartialEq, Clone)]
197pub enum RemoveMembersError<StorageError> {
198    /// See [`LibraryError`] for more details.
199    #[error(transparent)]
200    LibraryError(#[from] LibraryError),
201    /// See [`EmptyInputError`] for more details.
202    #[error(transparent)]
203    EmptyInput(#[from] EmptyInputError),
204    /// See [`CreateCommitError`] for more details.
205    #[error(transparent)]
206    CreateCommitError(#[from] CreateCommitError),
207    /// See [`CommitBuilderStageError`] for more details.
208    #[error(transparent)]
209    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
210    /// See [`MlsGroupStateError`] for more details.
211    #[error(transparent)]
212    GroupStateError(#[from] MlsGroupStateError),
213    /// The member that should be removed can not be found.
214    #[error("The member that should be removed can not be found.")]
215    UnknownMember,
216    /// Error writing to storage
217    #[error("Error writing to storage: {0}")]
218    StorageError(StorageError),
219}
220
221/// Leave group error
222#[derive(Error, Debug, PartialEq, Clone)]
223pub enum LeaveGroupError<StorageError> {
224    /// See [`LibraryError`] for more details.
225    #[error(transparent)]
226    LibraryError(#[from] LibraryError),
227    /// See [`MlsGroupStateError`] for more details.
228    #[error(transparent)]
229    GroupStateError(#[from] MlsGroupStateError),
230    /// An error ocurred while writing to storage
231    #[error("An error ocurred while writing to storage")]
232    StorageError(StorageError),
233    /// SelfRemove not allowed with pure ciphertext outgoing wire format policy.
234    #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
235    CannotSelfRemoveWithPureCiphertext,
236}
237
238/// Self update error
239#[derive(Error, Debug, PartialEq, Clone)]
240pub enum SelfUpdateError<StorageError> {
241    /// See [`LibraryError`] for more details.
242    #[error(transparent)]
243    LibraryError(#[from] LibraryError),
244    /// See [`CreateCommitError`] for more details.
245    #[error(transparent)]
246    CreateCommitError(#[from] CreateCommitError),
247    /// See [`CommitBuilderStageError`] for more details.
248    #[error(transparent)]
249    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
250    /// See [`MlsGroupStateError`] for more details.
251    #[error(transparent)]
252    GroupStateError(#[from] MlsGroupStateError),
253    /// Error accessing the storage.
254    #[error("Error accessing the storage.")]
255    StorageError(StorageError),
256}
257
258/// Propose self update error
259#[derive(Error, Debug, PartialEq, Clone)]
260pub enum ProposeSelfUpdateError<StorageError> {
261    /// See [`LibraryError`] for more details.
262    #[error(transparent)]
263    LibraryError(#[from] LibraryError),
264
265    /// See [`MlsGroupStateError`] for more details.
266    #[error(transparent)]
267    GroupStateError(#[from] MlsGroupStateError),
268    /// Error accessing storage.
269    #[error("Error accessing storage.")]
270    StorageError(StorageError),
271    /// See [`PublicTreeError`] for more details.
272    #[error(transparent)]
273    PublicTreeError(#[from] PublicTreeError),
274    /// See [`LeafNodeUpdateError`] for more details.
275    #[error(transparent)]
276    LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
277}
278
279/// Commit to pending proposals error
280#[derive(Error, Debug, PartialEq, Clone)]
281pub enum CommitToPendingProposalsError<StorageError> {
282    /// See [`LibraryError`] for more details.
283    #[error(transparent)]
284    LibraryError(#[from] LibraryError),
285    /// See [`CreateCommitError`] for more details.
286    #[error(transparent)]
287    CreateCommitError(#[from] CreateCommitError),
288    /// See [`CommitBuilderStageError`] for more details.
289    #[error(transparent)]
290    CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
291    /// See [`MlsGroupStateError`] for more details.
292    #[error(transparent)]
293    GroupStateError(#[from] MlsGroupStateError),
294    /// Error writing to storage
295    #[error("Error writing to storage: {0}")]
296    StorageError(StorageError),
297}
298
299/// Errors that can happen when exporting a group info object.
300#[derive(Error, Debug, PartialEq, Clone)]
301pub enum ExportGroupInfoError {
302    /// See [`LibraryError`] for more details.
303    #[error(transparent)]
304    LibraryError(#[from] LibraryError),
305    /// See [`MlsGroupStateError`] for more details.
306    #[error(transparent)]
307    GroupStateError(#[from] MlsGroupStateError),
308}
309
310/// Export secret error
311#[derive(Error, Debug, PartialEq, Clone)]
312pub enum ExportSecretError {
313    /// See [`LibraryError`] for more details.
314    #[error(transparent)]
315    LibraryError(#[from] LibraryError),
316    /// The requested key length is too long.
317    #[error("The requested key length is too long.")]
318    KeyLengthTooLong,
319    /// See [`MlsGroupStateError`] for more details.
320    #[error(transparent)]
321    GroupStateError(#[from] MlsGroupStateError),
322}
323
324/// Propose PSK error
325#[derive(Error, Debug, PartialEq, Clone)]
326pub enum ProposePskError {
327    /// See [`PskError`] for more details.
328    #[error(transparent)]
329    Psk(#[from] PskError),
330    /// See [`MlsGroupStateError`] for more details.
331    #[error(transparent)]
332    GroupStateError(#[from] MlsGroupStateError),
333    /// See [`LibraryError`] for more details.
334    #[error(transparent)]
335    LibraryError(#[from] LibraryError),
336}
337
338/// Proposal error
339#[derive(Error, Debug, PartialEq, Clone)]
340pub enum ProposalError<StorageError> {
341    /// See [`LibraryError`] for more details.
342    #[error(transparent)]
343    LibraryError(#[from] LibraryError),
344    /// See [`ProposeAddMemberError`] for more details.
345    #[error(transparent)]
346    ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
347    /// See [`CreateAddProposalError`] for more details.
348    #[error(transparent)]
349    CreateAddProposalError(#[from] CreateAddProposalError),
350    /// See [`ProposeSelfUpdateError`] for more details.
351    #[error(transparent)]
352    ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
353    /// See [`ProposeRemoveMemberError`] for more details.
354    #[error(transparent)]
355    ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
356    /// See [`MlsGroupStateError`] for more details.
357    #[error(transparent)]
358    GroupStateError(#[from] MlsGroupStateError),
359    /// See [`ValidationError`] for more details.
360    #[error(transparent)]
361    ValidationError(#[from] ValidationError),
362    /// See [`CreateGroupContextExtProposalError`] for more details.
363    #[error(transparent)]
364    CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
365    /// Error writing proposal to storage.
366    #[error("error writing proposal to storage")]
367    StorageError(StorageError),
368}
369
370/// Remove proposal error
371#[derive(Error, Debug, PartialEq, Clone)]
372pub enum RemoveProposalError<StorageError> {
373    /// Couldn't find the proposal for the given `ProposalRef`.
374    #[error("Couldn't find the proposal for the given `ProposalRef`")]
375    ProposalNotFound,
376    /// Error erasing proposal from storage.
377    #[error("error writing proposal to storage")]
378    Storage(StorageError),
379}