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 #[cfg(feature = "extensions-draft-08")]
148 #[error("malformed SafeAAD prefix in authenticated_data")]
149 MalformedSafeAad,
150}
151
152#[derive(Error, Debug, PartialEq, Clone)]
154pub enum ProcessMessageError<StorageError> {
155 #[error(transparent)]
157 LibraryError(#[from] LibraryError),
158 #[error("Error writing to storage: {0}")]
160 StorageError(StorageError),
161 #[error("The message's wire format is incompatible with the group's wire format policy.")]
163 IncompatibleWireFormat,
164 #[error(transparent)]
166 ValidationError(#[from] ValidationError),
167 #[error(transparent)]
169 GroupStateError(#[from] MlsGroupStateError),
170 #[error(transparent)]
172 InvalidCommit(#[from] StageCommitError),
173 #[error("External application messages are not permitted.")]
175 UnauthorizedExternalApplicationMessage,
176 #[error("Commit messages from external senders are not permitted.")]
178 UnauthorizedExternalCommitMessage,
179 #[error("The proposal is invalid for the Sender of type External")]
181 UnsupportedProposalType,
182
183 #[cfg(feature = "extensions-draft-08")]
185 #[error("Use `_with_app_data_update` functions for handling AppDataUpdate proposals")]
186 FoundAppDataUpdateProposal,
187
188 #[cfg(feature = "extensions-draft-08")]
191 #[error("malformed SafeAAD prefix in authenticated_data")]
192 MalformedSafeAad,
193}
194
195#[cfg(not(feature = "virtual-clients-draft"))]
197#[derive(Error, Debug, PartialEq, Clone)]
198pub enum CreateMessageError {
199 #[error(transparent)]
201 LibraryError(#[from] LibraryError),
202 #[error(transparent)]
204 GroupStateError(#[from] MlsGroupStateError),
205}
206
207#[derive(Error, Debug, PartialEq, Clone)]
209pub enum AddMembersError<StorageError> {
210 #[error(transparent)]
212 LibraryError(#[from] LibraryError),
213 #[error(transparent)]
215 EmptyInput(#[from] EmptyInputError),
216 #[error(transparent)]
218 CreateCommitError(#[from] CreateCommitError),
219 #[error(transparent)]
221 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
222 #[error(transparent)]
224 GroupStateError(#[from] MlsGroupStateError),
225 #[error("Error writing to storage")]
227 StorageError(StorageError),
228}
229
230#[derive(Error, Debug, PartialEq, Clone)]
232pub enum SwapMembersError<StorageError> {
233 #[error("Number of added and removed members is not the same")]
235 InvalidInput,
236
237 #[error(transparent)]
239 EmptyInput(#[from] EmptyInputError),
240
241 #[error(transparent)]
243 GroupStateError(#[from] MlsGroupStateError),
244
245 #[error(transparent)]
247 LibraryError(#[from] LibraryError),
248
249 #[error("The member that should be removed can not be found.")]
251 UnknownMember,
252
253 #[error("Error writing to storage: {0}")]
255 StorageError(StorageError),
256
257 #[error(transparent)]
259 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
260
261 #[error(transparent)]
263 CreateCommitError(#[from] CreateCommitError),
264}
265
266#[derive(Error, Debug, PartialEq, Clone)]
268pub enum ProposeAddMemberError<StorageError> {
269 #[error(transparent)]
271 LibraryError(#[from] LibraryError),
272 #[error("The new member does not support all required extensions.")]
274 UnsupportedExtensions,
275 #[error(transparent)]
277 GroupStateError(#[from] MlsGroupStateError),
278 #[error(transparent)]
280 LeafNodeValidation(#[from] LeafNodeValidationError),
281 #[error("Error writing to storage: {0}")]
283 StorageError(StorageError),
284}
285
286#[derive(Error, Debug, PartialEq, Clone)]
288pub enum ProposeRemoveMemberError<StorageError> {
289 #[error(transparent)]
291 LibraryError(#[from] LibraryError),
292 #[error(transparent)]
294 GroupStateError(#[from] MlsGroupStateError),
295 #[error("The member that should be removed can not be found.")]
297 UnknownMember,
298 #[error("Error writing to storage: {0}")]
300 StorageError(StorageError),
301}
302
303#[derive(Error, Debug, PartialEq, Clone)]
305pub enum RemoveMembersError<StorageError> {
306 #[error(transparent)]
308 LibraryError(#[from] LibraryError),
309 #[error(transparent)]
311 EmptyInput(#[from] EmptyInputError),
312 #[error(transparent)]
314 CreateCommitError(#[from] CreateCommitError),
315 #[error(transparent)]
317 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
318 #[error(transparent)]
320 GroupStateError(#[from] MlsGroupStateError),
321 #[error("The member that should be removed can not be found.")]
323 UnknownMember,
324 #[error("Error writing to storage: {0}")]
326 StorageError(StorageError),
327}
328
329#[derive(Error, Debug, PartialEq, Clone)]
331pub enum LeaveGroupError<StorageError> {
332 #[error(transparent)]
334 LibraryError(#[from] LibraryError),
335 #[error(transparent)]
337 GroupStateError(#[from] MlsGroupStateError),
338 #[error("An error ocurred while writing to storage")]
340 StorageError(StorageError),
341 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
343 CannotSelfRemoveWithPureCiphertext,
344}
345
346#[derive(Error, Debug, PartialEq, Clone)]
348pub enum SelfUpdateError<StorageError> {
349 #[error(transparent)]
351 LibraryError(#[from] LibraryError),
352 #[error(transparent)]
354 CreateCommitError(#[from] CreateCommitError),
355 #[error(transparent)]
357 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
358 #[error(transparent)]
360 GroupStateError(#[from] MlsGroupStateError),
361 #[error("Error accessing the storage.")]
363 StorageError(StorageError),
364}
365
366#[derive(Error, Debug, PartialEq, Clone)]
368pub enum ProposeSelfUpdateError<StorageError> {
369 #[error(transparent)]
371 LibraryError(#[from] LibraryError),
372
373 #[error(transparent)]
375 GroupStateError(#[from] MlsGroupStateError),
376 #[error("Error accessing storage.")]
378 StorageError(StorageError),
379 #[error(transparent)]
381 PublicTreeError(#[from] PublicTreeError),
382 #[error(transparent)]
384 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
385 #[error("The updated leaf node does not support all group context extensions.")]
387 UnsupportedGroupContextExtensions,
388 #[error("Mismatched credential_with_key between leaf_node_parameters and new_signer")]
391 InvalidLeafNodeParameters,
392 #[error("Mismatched ciphersuite between new_signer and the group")]
395 InvalidSignerCiphersuite,
396}
397
398#[derive(Error, Debug, PartialEq, Clone)]
400pub enum CommitToPendingProposalsError<StorageError> {
401 #[error(transparent)]
403 LibraryError(#[from] LibraryError),
404 #[error(transparent)]
406 CreateCommitError(#[from] CreateCommitError),
407 #[error(transparent)]
409 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
410 #[error(transparent)]
412 GroupStateError(#[from] MlsGroupStateError),
413 #[error("Error writing to storage: {0}")]
415 StorageError(StorageError),
416}
417
418#[derive(Error, Debug, PartialEq, Clone)]
420pub enum ExportGroupInfoError {
421 #[error(transparent)]
423 LibraryError(#[from] LibraryError),
424 #[error(transparent)]
426 GroupStateError(#[from] MlsGroupStateError),
427 #[error(transparent)]
429 InvalidExtensionError(#[from] InvalidExtensionError),
430}
431
432#[cfg(feature = "extensions-draft-08")]
434#[derive(Error, Debug, PartialEq, Clone)]
435pub enum SafeExportSecretError<StorageError> {
436 #[error(transparent)]
438 GroupState(#[from] MlsGroupStateError),
439 #[error(transparent)]
441 ApplicationExportTree(#[from] ApplicationExportTreeError),
442 #[error("Group doesn't support application exports.")]
444 Unsupported,
445 #[error("Error accessing storage: {0}")]
447 Storage(StorageError),
448}
449
450#[cfg(feature = "extensions-draft-08")]
452#[derive(Error, Debug, PartialEq, Clone)]
453pub enum ProcessedMessageSafeExportSecretError {
454 #[error(transparent)]
456 SafeExportSecretError(#[from] StagedSafeExportSecretError),
457 #[error("Processed message is not a commit.")]
459 NotACommit,
460}
461
462#[cfg(feature = "extensions-draft-08")]
464#[derive(Error, Debug, PartialEq, Clone)]
465pub enum PendingSafeExportSecretError<StorageError> {
466 #[error(transparent)]
468 SafeExportSecretError(#[from] StagedSafeExportSecretError),
469 #[error("No pending commit.")]
471 NoPendingCommit,
472 #[error("Error accessing storage: {0}")]
474 Storage(StorageError),
475 #[error("Only group members can export secrets.")]
477 NotGroupMember,
478}
479
480#[cfg(feature = "extensions-draft-08")]
482#[derive(Error, Debug, PartialEq, Clone)]
483pub enum StagedSafeExportSecretError {
484 #[error("Only group members can export secrets.")]
486 NotGroupMember,
487 #[error(transparent)]
489 ApplicationExportTree(#[from] ApplicationExportTreeError),
490 #[error("Group doesn't support application exports.")]
492 Unsupported,
493}
494
495#[derive(Error, Debug, PartialEq, Clone)]
497pub enum ExportSecretError {
498 #[error(transparent)]
500 LibraryError(#[from] LibraryError),
501 #[error("The requested key length is too long.")]
503 KeyLengthTooLong,
504 #[error(transparent)]
506 GroupStateError(#[from] MlsGroupStateError),
507}
508
509#[derive(Error, Debug, PartialEq, Clone)]
511pub enum ProposePskError {
512 #[error(transparent)]
514 Psk(#[from] PskError),
515 #[error(transparent)]
517 GroupStateError(#[from] MlsGroupStateError),
518 #[error(transparent)]
520 LibraryError(#[from] LibraryError),
521}
522
523#[derive(Error, Debug, PartialEq, Clone)]
525pub enum ProposalError<StorageError> {
526 #[error(transparent)]
528 LibraryError(#[from] LibraryError),
529 #[error(transparent)]
531 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
532 #[error(transparent)]
534 CreateAddProposalError(#[from] CreateAddProposalError),
535 #[error(transparent)]
537 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
538 #[error(transparent)]
540 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
541 #[error(transparent)]
543 GroupStateError(#[from] MlsGroupStateError),
544 #[error(transparent)]
546 ValidationError(#[from] ValidationError),
547 #[error(transparent)]
549 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
550 #[error(transparent)]
552 InvalidExtension(#[from] InvalidExtensionError),
553 #[error("error writing proposal to storage")]
555 StorageError(StorageError),
556}
557
558#[derive(Error, Debug, PartialEq, Clone)]
560pub enum RemoveProposalError<StorageError> {
561 #[error("Couldn't find the proposal for the given `ProposalRef`")]
563 ProposalNotFound,
564 #[error("error writing proposal to storage")]
566 Storage(StorageError),
567}
568
569#[cfg(feature = "virtual-clients-draft")]
570pub use virtual_clients_draft::*;
571
572#[cfg(feature = "virtual-clients-draft")]
573mod virtual_clients_draft {
574 use thiserror::Error;
575
576 use super::MlsGroupStateError;
577 use crate::error::LibraryError;
578 use crate::framing::MessageEncryptionError;
579 use crate::tree::secret_tree::SecretTreeError;
580
581 #[derive(Error, Debug, PartialEq, Clone)]
583 pub enum CreateMessageError<StorageError> {
584 #[error(transparent)]
586 LibraryError(#[from] LibraryError),
587 #[error(transparent)]
589 GroupStateError(#[from] MlsGroupStateError),
590 #[error(transparent)]
592 MessageEncryptionError(#[from] MessageEncryptionError<StorageError>),
593 #[error("Error writing to storage: {0}")]
595 StorageError(StorageError),
596 }
597
598 #[derive(Error, Debug, PartialEq, Clone)]
600 pub enum ConfirmMessageError<StorageError> {
601 #[error(transparent)]
603 SecretTreeError(#[from] SecretTreeError),
604 #[error("Error writing to storage: {0}")]
606 StorageError(StorageError),
607 }
608
609 impl<StorageError> From<ConfirmMessageError<StorageError>> for CreateMessageError<StorageError> {
610 fn from(err: ConfirmMessageError<StorageError>) -> Self {
611 match err {
612 ConfirmMessageError::SecretTreeError(e) => {
613 CreateMessageError::MessageEncryptionError(
614 MessageEncryptionError::SecretTreeError(e),
615 )
616 }
617 ConfirmMessageError::StorageError(e) => CreateMessageError::StorageError(e),
618 }
619 }
620 }
621}