1use 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#[derive(Error, Debug, PartialEq, Clone)]
35pub enum NewGroupError<StorageError> {
36 #[error(transparent)]
38 LibraryError(#[from] LibraryError),
39 #[error("No matching KeyPackage was found in the key store.")]
41 NoMatchingKeyPackage,
42 #[error("Error accessing the storage.")]
44 StorageError(StorageError),
45 #[error("Unsupported proposal type in required capabilities.")]
47 UnsupportedProposalType,
48 #[error("Unsupported extension type in required capabilities.")]
50 UnsupportedExtensionType,
51 #[error("Invalid extensions set in configuration")]
53 InvalidExtensions(#[from] InvalidExtensionError),
54 #[error("A group with the given GroupId already exists.")]
56 GroupAlreadyExists,
57}
58
59#[derive(Error, Debug, PartialEq, Eq, Clone)]
61pub enum EmptyInputError {
62 #[error("An empty list of KeyPackages was provided.")]
64 AddMembers,
65 #[error("An empty list of KeyPackage references was provided.")]
67 RemoveMembers,
68}
69
70#[derive(Error, Debug, PartialEq, Clone)]
72pub enum MlsGroupStateError {
73 #[error(transparent)]
75 LibraryError(#[from] LibraryError),
76 #[error("Tried to use a group after being evicted from it.")]
78 UseAfterEviction,
79 #[error("Can't create message because a pending proposal exists.")]
81 PendingProposal,
82 #[error("Can't execute operation because a pending commit exists.")]
84 PendingCommit,
85 #[error("Can't execute operation because there is no pending commit")]
87 NoPendingCommit,
88 #[error("Requested pending proposal hasn't been found in local pending proposals.")]
90 PendingProposalNotFound,
91}
92
93#[derive(Error, Debug, PartialEq, Clone)]
95pub enum MergePendingCommitError<StorageError> {
96 #[error(transparent)]
98 MlsGroupStateError(#[from] MlsGroupStateError),
99 #[error(transparent)]
101 MergeCommitError(#[from] MergeCommitError<StorageError>),
102}
103
104#[derive(Error, Debug, PartialEq, Clone)]
106pub enum PublicProcessMessageError {
107 #[error(transparent)]
109 LibraryError(#[from] LibraryError),
110 #[error("The message's wire format is incompatible with the group's wire format policy.")]
112 IncompatibleWireFormat,
113 #[error(transparent)]
115 ValidationError(#[from] ValidationError),
116 #[error(transparent)]
118 InvalidCommit(#[from] StageCommitError),
119 #[error("External application messages are not permitted.")]
121 UnauthorizedExternalApplicationMessage,
122 #[error("Commit messages from external senders are not permitted.")]
124 UnauthorizedExternalCommitMessage,
125 #[error("The proposal is invalid for the Sender of type External")]
127 UnsupportedProposalType,
128}
129
130#[derive(Error, Debug, PartialEq, Clone)]
132pub enum ProcessMessageError<StorageError> {
133 #[error(transparent)]
135 LibraryError(#[from] LibraryError),
136 #[error("Error writing to storage: {0}")]
138 StorageError(StorageError),
139 #[error("The message's wire format is incompatible with the group's wire format policy.")]
141 IncompatibleWireFormat,
142 #[error(transparent)]
144 ValidationError(#[from] ValidationError),
145 #[error(transparent)]
147 GroupStateError(#[from] MlsGroupStateError),
148 #[error(transparent)]
150 InvalidCommit(#[from] StageCommitError),
151 #[error("External application messages are not permitted.")]
153 UnauthorizedExternalApplicationMessage,
154 #[error("Commit messages from external senders are not permitted.")]
156 UnauthorizedExternalCommitMessage,
157 #[error("The proposal is invalid for the Sender of type External")]
159 UnsupportedProposalType,
160
161 #[cfg(feature = "extensions-draft-08")]
163 #[error("Use `_with_app_data_update` functions for handling AppDataUpdate proposals")]
164 FoundAppDataUpdateProposal,
165}
166
167#[derive(Error, Debug, PartialEq, Clone)]
169pub enum CreateMessageError {
170 #[error(transparent)]
172 LibraryError(#[from] LibraryError),
173 #[error(transparent)]
175 GroupStateError(#[from] MlsGroupStateError),
176}
177
178#[derive(Error, Debug, PartialEq, Clone)]
180pub enum AddMembersError<StorageError> {
181 #[error(transparent)]
183 LibraryError(#[from] LibraryError),
184 #[error(transparent)]
186 EmptyInput(#[from] EmptyInputError),
187 #[error(transparent)]
189 CreateCommitError(#[from] CreateCommitError),
190 #[error(transparent)]
192 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
193 #[error(transparent)]
195 GroupStateError(#[from] MlsGroupStateError),
196 #[error("Error writing to storage")]
198 StorageError(StorageError),
199}
200
201#[derive(Error, Debug, PartialEq, Clone)]
203pub enum SwapMembersError<StorageError> {
204 #[error("Number of added and removed members is not the same")]
206 InvalidInput,
207
208 #[error(transparent)]
210 EmptyInput(#[from] EmptyInputError),
211
212 #[error(transparent)]
214 GroupStateError(#[from] MlsGroupStateError),
215
216 #[error(transparent)]
218 LibraryError(#[from] LibraryError),
219
220 #[error("The member that should be removed can not be found.")]
222 UnknownMember,
223
224 #[error("Error writing to storage: {0}")]
226 StorageError(StorageError),
227
228 #[error(transparent)]
230 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
231
232 #[error(transparent)]
234 CreateCommitError(#[from] CreateCommitError),
235}
236
237#[derive(Error, Debug, PartialEq, Clone)]
239pub enum ProposeAddMemberError<StorageError> {
240 #[error(transparent)]
242 LibraryError(#[from] LibraryError),
243 #[error("The new member does not support all required extensions.")]
245 UnsupportedExtensions,
246 #[error(transparent)]
248 GroupStateError(#[from] MlsGroupStateError),
249 #[error(transparent)]
251 LeafNodeValidation(#[from] LeafNodeValidationError),
252 #[error("Error writing to storage: {0}")]
254 StorageError(StorageError),
255}
256
257#[derive(Error, Debug, PartialEq, Clone)]
259pub enum ProposeRemoveMemberError<StorageError> {
260 #[error(transparent)]
262 LibraryError(#[from] LibraryError),
263 #[error(transparent)]
265 GroupStateError(#[from] MlsGroupStateError),
266 #[error("The member that should be removed can not be found.")]
268 UnknownMember,
269 #[error("Error writing to storage: {0}")]
271 StorageError(StorageError),
272}
273
274#[derive(Error, Debug, PartialEq, Clone)]
276pub enum RemoveMembersError<StorageError> {
277 #[error(transparent)]
279 LibraryError(#[from] LibraryError),
280 #[error(transparent)]
282 EmptyInput(#[from] EmptyInputError),
283 #[error(transparent)]
285 CreateCommitError(#[from] CreateCommitError),
286 #[error(transparent)]
288 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
289 #[error(transparent)]
291 GroupStateError(#[from] MlsGroupStateError),
292 #[error("The member that should be removed can not be found.")]
294 UnknownMember,
295 #[error("Error writing to storage: {0}")]
297 StorageError(StorageError),
298}
299
300#[derive(Error, Debug, PartialEq, Clone)]
302pub enum LeaveGroupError<StorageError> {
303 #[error(transparent)]
305 LibraryError(#[from] LibraryError),
306 #[error(transparent)]
308 GroupStateError(#[from] MlsGroupStateError),
309 #[error("An error ocurred while writing to storage")]
311 StorageError(StorageError),
312 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
314 CannotSelfRemoveWithPureCiphertext,
315}
316
317#[derive(Error, Debug, PartialEq, Clone)]
319pub enum SelfUpdateError<StorageError> {
320 #[error(transparent)]
322 LibraryError(#[from] LibraryError),
323 #[error(transparent)]
325 CreateCommitError(#[from] CreateCommitError),
326 #[error(transparent)]
328 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
329 #[error(transparent)]
331 GroupStateError(#[from] MlsGroupStateError),
332 #[error("Error accessing the storage.")]
334 StorageError(StorageError),
335}
336
337#[derive(Error, Debug, PartialEq, Clone)]
339pub enum ProposeSelfUpdateError<StorageError> {
340 #[error(transparent)]
342 LibraryError(#[from] LibraryError),
343
344 #[error(transparent)]
346 GroupStateError(#[from] MlsGroupStateError),
347 #[error("Error accessing storage.")]
349 StorageError(StorageError),
350 #[error(transparent)]
352 PublicTreeError(#[from] PublicTreeError),
353 #[error(transparent)]
355 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
356 #[error("The updated leaf node does not support all group context extensions.")]
358 UnsupportedGroupContextExtensions,
359}
360
361#[derive(Error, Debug, PartialEq, Clone)]
363pub enum CommitToPendingProposalsError<StorageError> {
364 #[error(transparent)]
366 LibraryError(#[from] LibraryError),
367 #[error(transparent)]
369 CreateCommitError(#[from] CreateCommitError),
370 #[error(transparent)]
372 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
373 #[error(transparent)]
375 GroupStateError(#[from] MlsGroupStateError),
376 #[error("Error writing to storage: {0}")]
378 StorageError(StorageError),
379}
380
381#[derive(Error, Debug, PartialEq, Clone)]
383pub enum ExportGroupInfoError {
384 #[error(transparent)]
386 LibraryError(#[from] LibraryError),
387 #[error(transparent)]
389 GroupStateError(#[from] MlsGroupStateError),
390 #[error(transparent)]
392 InvalidExtensionError(#[from] InvalidExtensionError),
393}
394
395#[cfg(feature = "extensions-draft-08")]
397#[derive(Error, Debug, PartialEq, Clone)]
398pub enum SafeExportSecretError<StorageError> {
399 #[error(transparent)]
401 GroupState(#[from] MlsGroupStateError),
402 #[error(transparent)]
404 ApplicationExportTree(#[from] ApplicationExportTreeError),
405 #[error("Group doesn't support application exports.")]
407 Unsupported,
408 #[error("Error accessing storage: {0}")]
410 Storage(StorageError),
411}
412
413#[cfg(feature = "extensions-draft-08")]
415#[derive(Error, Debug, PartialEq, Clone)]
416pub enum ProcessedMessageSafeExportSecretError {
417 #[error(transparent)]
419 SafeExportSecretError(#[from] StagedSafeExportSecretError),
420 #[error("Processed message is not a commit.")]
422 NotACommit,
423}
424
425#[cfg(feature = "extensions-draft-08")]
427#[derive(Error, Debug, PartialEq, Clone)]
428pub enum PendingSafeExportSecretError<StorageError> {
429 #[error(transparent)]
431 SafeExportSecretError(#[from] StagedSafeExportSecretError),
432 #[error("No pending commit.")]
434 NoPendingCommit,
435 #[error("Error accessing storage: {0}")]
437 Storage(StorageError),
438 #[error("Only group members can export secrets.")]
440 NotGroupMember,
441}
442
443#[cfg(feature = "extensions-draft-08")]
445#[derive(Error, Debug, PartialEq, Clone)]
446pub enum StagedSafeExportSecretError {
447 #[error("Only group members can export secrets.")]
449 NotGroupMember,
450 #[error(transparent)]
452 ApplicationExportTree(#[from] ApplicationExportTreeError),
453 #[error("Group doesn't support application exports.")]
455 Unsupported,
456}
457
458#[derive(Error, Debug, PartialEq, Clone)]
460pub enum ExportSecretError {
461 #[error(transparent)]
463 LibraryError(#[from] LibraryError),
464 #[error("The requested key length is too long.")]
466 KeyLengthTooLong,
467 #[error(transparent)]
469 GroupStateError(#[from] MlsGroupStateError),
470}
471
472#[derive(Error, Debug, PartialEq, Clone)]
474pub enum ProposePskError {
475 #[error(transparent)]
477 Psk(#[from] PskError),
478 #[error(transparent)]
480 GroupStateError(#[from] MlsGroupStateError),
481 #[error(transparent)]
483 LibraryError(#[from] LibraryError),
484}
485
486#[derive(Error, Debug, PartialEq, Clone)]
488pub enum ProposalError<StorageError> {
489 #[error(transparent)]
491 LibraryError(#[from] LibraryError),
492 #[error(transparent)]
494 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
495 #[error(transparent)]
497 CreateAddProposalError(#[from] CreateAddProposalError),
498 #[error(transparent)]
500 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
501 #[error(transparent)]
503 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
504 #[error(transparent)]
506 GroupStateError(#[from] MlsGroupStateError),
507 #[error(transparent)]
509 ValidationError(#[from] ValidationError),
510 #[error(transparent)]
512 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
513 #[error(transparent)]
515 InvalidExtension(#[from] InvalidExtensionError),
516 #[error("error writing proposal to storage")]
518 StorageError(StorageError),
519}
520
521#[derive(Error, Debug, PartialEq, Clone)]
523pub enum RemoveProposalError<StorageError> {
524 #[error("Couldn't find the proposal for the given `ProposalRef`")]
526 ProposalNotFound,
527 #[error("error writing proposal to storage")]
529 Storage(StorageError),
530}