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 DeletePastEpochSecretsError<StorageError> {
62 #[error(transparent)]
64 StorageError(#[from] StorageError),
65}
66
67#[derive(Error, Debug, PartialEq, Eq, Clone)]
69pub enum SetPastEpochDeletionPolicyError<StorageError> {
70 #[error(transparent)]
72 StorageError(#[from] StorageError),
73}
74
75#[derive(Error, Debug, PartialEq, Eq, Clone)]
77pub enum EmptyInputError {
78 #[error("An empty list of KeyPackages was provided.")]
80 AddMembers,
81 #[error("An empty list of KeyPackage references was provided.")]
83 RemoveMembers,
84}
85
86#[derive(Error, Debug, PartialEq, Clone)]
88pub enum MlsGroupStateError {
89 #[error(transparent)]
91 LibraryError(#[from] LibraryError),
92 #[error("Tried to use a group after being evicted from it.")]
94 UseAfterEviction,
95 #[error("Can't create message because a pending proposal exists.")]
97 PendingProposal,
98 #[error("Can't execute operation because a pending commit exists.")]
100 PendingCommit,
101 #[error("Can't execute operation because there is no pending commit")]
103 NoPendingCommit,
104 #[error("Requested pending proposal hasn't been found in local pending proposals.")]
106 PendingProposalNotFound,
107}
108
109#[derive(Error, Debug, PartialEq, Clone)]
111pub enum MergePendingCommitError<StorageError> {
112 #[error(transparent)]
114 MlsGroupStateError(#[from] MlsGroupStateError),
115 #[error(transparent)]
117 MergeCommitError(#[from] MergeCommitError<StorageError>),
118}
119
120#[derive(Error, Debug, PartialEq, Clone)]
122pub enum PublicProcessMessageError {
123 #[error(transparent)]
125 LibraryError(#[from] LibraryError),
126 #[error("The message's wire format is incompatible with the group's wire format policy.")]
128 IncompatibleWireFormat,
129 #[error(transparent)]
131 ValidationError(#[from] ValidationError),
132 #[error(transparent)]
134 InvalidCommit(#[from] StageCommitError),
135 #[error("External application messages are not permitted.")]
137 UnauthorizedExternalApplicationMessage,
138 #[error("Commit messages from external senders are not permitted.")]
140 UnauthorizedExternalCommitMessage,
141 #[error("The proposal is invalid for the Sender of type External")]
143 UnsupportedProposalType,
144}
145
146#[derive(Error, Debug, PartialEq, Clone)]
148pub enum ProcessMessageError<StorageError> {
149 #[error(transparent)]
151 LibraryError(#[from] LibraryError),
152 #[error("Error writing to storage: {0}")]
154 StorageError(StorageError),
155 #[error("The message's wire format is incompatible with the group's wire format policy.")]
157 IncompatibleWireFormat,
158 #[error(transparent)]
160 ValidationError(#[from] ValidationError),
161 #[error(transparent)]
163 GroupStateError(#[from] MlsGroupStateError),
164 #[error(transparent)]
166 InvalidCommit(#[from] StageCommitError),
167 #[error("External application messages are not permitted.")]
169 UnauthorizedExternalApplicationMessage,
170 #[error("Commit messages from external senders are not permitted.")]
172 UnauthorizedExternalCommitMessage,
173 #[error("The proposal is invalid for the Sender of type External")]
175 UnsupportedProposalType,
176
177 #[cfg(feature = "extensions-draft-08")]
179 #[error("Use `_with_app_data_update` functions for handling AppDataUpdate proposals")]
180 FoundAppDataUpdateProposal,
181}
182
183#[derive(Error, Debug, PartialEq, Clone)]
185pub enum CreateMessageError {
186 #[error(transparent)]
188 LibraryError(#[from] LibraryError),
189 #[error(transparent)]
191 GroupStateError(#[from] MlsGroupStateError),
192}
193
194#[derive(Error, Debug, PartialEq, Clone)]
196pub enum AddMembersError<StorageError> {
197 #[error(transparent)]
199 LibraryError(#[from] LibraryError),
200 #[error(transparent)]
202 EmptyInput(#[from] EmptyInputError),
203 #[error(transparent)]
205 CreateCommitError(#[from] CreateCommitError),
206 #[error(transparent)]
208 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
209 #[error(transparent)]
211 GroupStateError(#[from] MlsGroupStateError),
212 #[error("Error writing to storage")]
214 StorageError(StorageError),
215}
216
217#[derive(Error, Debug, PartialEq, Clone)]
219pub enum SwapMembersError<StorageError> {
220 #[error("Number of added and removed members is not the same")]
222 InvalidInput,
223
224 #[error(transparent)]
226 EmptyInput(#[from] EmptyInputError),
227
228 #[error(transparent)]
230 GroupStateError(#[from] MlsGroupStateError),
231
232 #[error(transparent)]
234 LibraryError(#[from] LibraryError),
235
236 #[error("The member that should be removed can not be found.")]
238 UnknownMember,
239
240 #[error("Error writing to storage: {0}")]
242 StorageError(StorageError),
243
244 #[error(transparent)]
246 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
247
248 #[error(transparent)]
250 CreateCommitError(#[from] CreateCommitError),
251}
252
253#[derive(Error, Debug, PartialEq, Clone)]
255pub enum ProposeAddMemberError<StorageError> {
256 #[error(transparent)]
258 LibraryError(#[from] LibraryError),
259 #[error("The new member does not support all required extensions.")]
261 UnsupportedExtensions,
262 #[error(transparent)]
264 GroupStateError(#[from] MlsGroupStateError),
265 #[error(transparent)]
267 LeafNodeValidation(#[from] LeafNodeValidationError),
268 #[error("Error writing to storage: {0}")]
270 StorageError(StorageError),
271}
272
273#[derive(Error, Debug, PartialEq, Clone)]
275pub enum ProposeRemoveMemberError<StorageError> {
276 #[error(transparent)]
278 LibraryError(#[from] LibraryError),
279 #[error(transparent)]
281 GroupStateError(#[from] MlsGroupStateError),
282 #[error("The member that should be removed can not be found.")]
284 UnknownMember,
285 #[error("Error writing to storage: {0}")]
287 StorageError(StorageError),
288}
289
290#[derive(Error, Debug, PartialEq, Clone)]
292pub enum RemoveMembersError<StorageError> {
293 #[error(transparent)]
295 LibraryError(#[from] LibraryError),
296 #[error(transparent)]
298 EmptyInput(#[from] EmptyInputError),
299 #[error(transparent)]
301 CreateCommitError(#[from] CreateCommitError),
302 #[error(transparent)]
304 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
305 #[error(transparent)]
307 GroupStateError(#[from] MlsGroupStateError),
308 #[error("The member that should be removed can not be found.")]
310 UnknownMember,
311 #[error("Error writing to storage: {0}")]
313 StorageError(StorageError),
314}
315
316#[derive(Error, Debug, PartialEq, Clone)]
318pub enum LeaveGroupError<StorageError> {
319 #[error(transparent)]
321 LibraryError(#[from] LibraryError),
322 #[error(transparent)]
324 GroupStateError(#[from] MlsGroupStateError),
325 #[error("An error ocurred while writing to storage")]
327 StorageError(StorageError),
328 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
330 CannotSelfRemoveWithPureCiphertext,
331}
332
333#[derive(Error, Debug, PartialEq, Clone)]
335pub enum SelfUpdateError<StorageError> {
336 #[error(transparent)]
338 LibraryError(#[from] LibraryError),
339 #[error(transparent)]
341 CreateCommitError(#[from] CreateCommitError),
342 #[error(transparent)]
344 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
345 #[error(transparent)]
347 GroupStateError(#[from] MlsGroupStateError),
348 #[error("Error accessing the storage.")]
350 StorageError(StorageError),
351}
352
353#[derive(Error, Debug, PartialEq, Clone)]
355pub enum ProposeSelfUpdateError<StorageError> {
356 #[error(transparent)]
358 LibraryError(#[from] LibraryError),
359
360 #[error(transparent)]
362 GroupStateError(#[from] MlsGroupStateError),
363 #[error("Error accessing storage.")]
365 StorageError(StorageError),
366 #[error(transparent)]
368 PublicTreeError(#[from] PublicTreeError),
369 #[error(transparent)]
371 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
372 #[error("The updated leaf node does not support all group context extensions.")]
374 UnsupportedGroupContextExtensions,
375}
376
377#[derive(Error, Debug, PartialEq, Clone)]
379pub enum CommitToPendingProposalsError<StorageError> {
380 #[error(transparent)]
382 LibraryError(#[from] LibraryError),
383 #[error(transparent)]
385 CreateCommitError(#[from] CreateCommitError),
386 #[error(transparent)]
388 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
389 #[error(transparent)]
391 GroupStateError(#[from] MlsGroupStateError),
392 #[error("Error writing to storage: {0}")]
394 StorageError(StorageError),
395}
396
397#[derive(Error, Debug, PartialEq, Clone)]
399pub enum ExportGroupInfoError {
400 #[error(transparent)]
402 LibraryError(#[from] LibraryError),
403 #[error(transparent)]
405 GroupStateError(#[from] MlsGroupStateError),
406 #[error(transparent)]
408 InvalidExtensionError(#[from] InvalidExtensionError),
409}
410
411#[cfg(feature = "extensions-draft-08")]
413#[derive(Error, Debug, PartialEq, Clone)]
414pub enum SafeExportSecretError<StorageError> {
415 #[error(transparent)]
417 GroupState(#[from] MlsGroupStateError),
418 #[error(transparent)]
420 ApplicationExportTree(#[from] ApplicationExportTreeError),
421 #[error("Group doesn't support application exports.")]
423 Unsupported,
424 #[error("Error accessing storage: {0}")]
426 Storage(StorageError),
427}
428
429#[cfg(feature = "extensions-draft-08")]
431#[derive(Error, Debug, PartialEq, Clone)]
432pub enum ProcessedMessageSafeExportSecretError {
433 #[error(transparent)]
435 SafeExportSecretError(#[from] StagedSafeExportSecretError),
436 #[error("Processed message is not a commit.")]
438 NotACommit,
439}
440
441#[cfg(feature = "extensions-draft-08")]
443#[derive(Error, Debug, PartialEq, Clone)]
444pub enum PendingSafeExportSecretError<StorageError> {
445 #[error(transparent)]
447 SafeExportSecretError(#[from] StagedSafeExportSecretError),
448 #[error("No pending commit.")]
450 NoPendingCommit,
451 #[error("Error accessing storage: {0}")]
453 Storage(StorageError),
454 #[error("Only group members can export secrets.")]
456 NotGroupMember,
457}
458
459#[cfg(feature = "extensions-draft-08")]
461#[derive(Error, Debug, PartialEq, Clone)]
462pub enum StagedSafeExportSecretError {
463 #[error("Only group members can export secrets.")]
465 NotGroupMember,
466 #[error(transparent)]
468 ApplicationExportTree(#[from] ApplicationExportTreeError),
469 #[error("Group doesn't support application exports.")]
471 Unsupported,
472}
473
474#[derive(Error, Debug, PartialEq, Clone)]
476pub enum ExportSecretError {
477 #[error(transparent)]
479 LibraryError(#[from] LibraryError),
480 #[error("The requested key length is too long.")]
482 KeyLengthTooLong,
483 #[error(transparent)]
485 GroupStateError(#[from] MlsGroupStateError),
486}
487
488#[derive(Error, Debug, PartialEq, Clone)]
490pub enum ProposePskError {
491 #[error(transparent)]
493 Psk(#[from] PskError),
494 #[error(transparent)]
496 GroupStateError(#[from] MlsGroupStateError),
497 #[error(transparent)]
499 LibraryError(#[from] LibraryError),
500}
501
502#[derive(Error, Debug, PartialEq, Clone)]
504pub enum ProposalError<StorageError> {
505 #[error(transparent)]
507 LibraryError(#[from] LibraryError),
508 #[error(transparent)]
510 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
511 #[error(transparent)]
513 CreateAddProposalError(#[from] CreateAddProposalError),
514 #[error(transparent)]
516 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
517 #[error(transparent)]
519 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
520 #[error(transparent)]
522 GroupStateError(#[from] MlsGroupStateError),
523 #[error(transparent)]
525 ValidationError(#[from] ValidationError),
526 #[error(transparent)]
528 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
529 #[error(transparent)]
531 InvalidExtension(#[from] InvalidExtensionError),
532 #[error("error writing proposal to storage")]
534 StorageError(StorageError),
535}
536
537#[derive(Error, Debug, PartialEq, Clone)]
539pub enum RemoveProposalError<StorageError> {
540 #[error("Couldn't find the proposal for the given `ProposalRef`")]
542 ProposalNotFound,
543 #[error("error writing proposal to storage")]
545 Storage(StorageError),
546}