1use openmls_traits::types::Ciphersuite;
9use thiserror::Error;
10
11use crate::{
12 error::LibraryError,
13 extensions::errors::InvalidExtensionError,
14 group::{
15 errors::{
16 CreateAddProposalError, CreateCommitError, MergeCommitError, StageCommitError,
17 ValidationError,
18 },
19 CommitBuilderStageError, CreateGroupContextExtProposalError,
20 },
21 schedule::errors::PskError,
22 treesync::{
23 errors::{LeafNodeValidationError, PublicTreeError},
24 node::leaf_node::LeafNodeUpdateError,
25 },
26};
27
28#[cfg(feature = "extensions-draft")]
29pub use crate::schedule::application_export_tree::ApplicationExportTreeError;
30
31#[cfg(doc)]
32use crate::group::GroupId;
33
34#[derive(Error, Debug, PartialEq, Clone)]
36pub enum NewGroupError<StorageError> {
37 #[error(transparent)]
39 LibraryError(#[from] LibraryError),
40 #[error("No matching KeyPackage was found in the key store.")]
42 NoMatchingKeyPackage,
43 #[error("Error accessing the storage.")]
45 StorageError(StorageError),
46 #[error("Unsupported proposal type in required capabilities.")]
48 UnsupportedProposalType,
49 #[error("Unsupported extension type in required capabilities.")]
51 UnsupportedExtensionType,
52 #[error("Invalid extensions set in configuration")]
54 InvalidExtensions(#[from] InvalidExtensionError),
55 #[error("A group with the given GroupId already exists.")]
57 GroupAlreadyExists,
58 #[error("Ciphersuite {0:?} is not supported by the crypto provider.")]
60 UnsupportedCiphersuite(Ciphersuite),
61 #[error(transparent)]
63 LeafNodeBuild(#[from] crate::treesync::node::leaf_node::LeafNodeBuildError),
64 #[cfg(feature = "virtual-clients-draft")]
66 #[error(transparent)]
67 VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
68 #[cfg(feature = "virtual-clients-draft")]
71 #[error(transparent)]
72 RegisterVcDerivationEpoch(#[from] RegisterVcDerivationEpochError<StorageError>),
73}
74
75#[derive(Error, Debug, PartialEq, Eq, Clone)]
77pub enum DeletePastEpochSecretsError<StorageError> {
78 #[error(transparent)]
80 StorageError(#[from] StorageError),
81}
82
83#[derive(Error, Debug, PartialEq, Eq, Clone)]
85pub enum SetPastEpochDeletionPolicyError<StorageError> {
86 #[error(transparent)]
88 StorageError(#[from] StorageError),
89}
90
91#[derive(Error, Debug, PartialEq, Eq, Clone)]
93pub enum EmptyInputError {
94 #[error("An empty list of KeyPackages was provided.")]
96 AddMembers,
97 #[error("An empty list of KeyPackage references was provided.")]
99 RemoveMembers,
100}
101
102#[derive(Error, Debug, PartialEq, Clone)]
104pub enum MlsGroupStateError {
105 #[error(transparent)]
107 LibraryError(#[from] LibraryError),
108 #[error("Tried to use a group after being evicted from it.")]
110 UseAfterEviction,
111 #[error("Can't create message because a pending proposal exists.")]
113 PendingProposal,
114 #[error("Can't execute operation because a pending commit exists.")]
116 PendingCommit,
117 #[error("Can't execute operation because there is no pending commit")]
119 NoPendingCommit,
120 #[error("Requested pending proposal hasn't been found in local pending proposals.")]
122 PendingProposalNotFound,
123}
124
125#[derive(Error, Debug, PartialEq, Clone)]
127pub enum MergePendingCommitError<StorageError> {
128 #[error(transparent)]
130 MlsGroupStateError(#[from] MlsGroupStateError),
131 #[error(transparent)]
133 MergeCommitError(#[from] MergeCommitError<StorageError>),
134}
135
136#[derive(Error, Debug, PartialEq, Clone)]
138pub enum PublicProcessMessageError {
139 #[error(transparent)]
141 LibraryError(#[from] LibraryError),
142 #[error("The message's wire format is incompatible with the group's wire format policy.")]
144 IncompatibleWireFormat,
145 #[error(transparent)]
147 ValidationError(#[from] ValidationError),
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")]
164 #[error("malformed SafeAAD prefix in authenticated_data")]
165 MalformedSafeAad,
166}
167
168#[derive(Error, Debug, PartialEq, Clone)]
170pub enum ProcessMessageError<StorageError> {
171 #[error(transparent)]
173 LibraryError(#[from] LibraryError),
174 #[error("Error writing to storage: {0}")]
176 StorageError(StorageError),
177 #[error("The message's wire format is incompatible with the group's wire format policy.")]
179 IncompatibleWireFormat,
180 #[error(transparent)]
182 ValidationError(#[from] ValidationError),
183 #[error(transparent)]
185 GroupStateError(#[from] MlsGroupStateError),
186 #[error(transparent)]
188 InvalidCommit(#[from] StageCommitError),
189 #[error("External application messages are not permitted.")]
191 UnauthorizedExternalApplicationMessage,
192 #[error("Commit messages from external senders are not permitted.")]
194 UnauthorizedExternalCommitMessage,
195 #[error("The proposal is invalid for the Sender of type External")]
197 UnsupportedProposalType,
198 #[cfg(feature = "extensions-draft")]
201 #[error("malformed SafeAAD prefix in authenticated_data")]
202 MalformedSafeAad,
203}
204
205#[cfg(not(feature = "virtual-clients-draft"))]
207#[derive(Error, Debug, PartialEq, Clone)]
208pub enum CreateMessageError {
209 #[error(transparent)]
211 LibraryError(#[from] LibraryError),
212 #[error(transparent)]
214 GroupStateError(#[from] MlsGroupStateError),
215}
216
217#[derive(Error, Debug, PartialEq, Clone)]
219pub enum AddMembersError<StorageError> {
220 #[error(transparent)]
222 LibraryError(#[from] LibraryError),
223 #[error(transparent)]
225 EmptyInput(#[from] EmptyInputError),
226 #[error(transparent)]
228 CreateCommitError(#[from] CreateCommitError),
229 #[error(transparent)]
231 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
232 #[error(transparent)]
234 GroupStateError(#[from] MlsGroupStateError),
235 #[error("Error writing to storage")]
237 StorageError(StorageError),
238}
239
240#[derive(Error, Debug, PartialEq, Clone)]
242pub enum SwapMembersError<StorageError> {
243 #[error("Number of added and removed members is not the same")]
245 InvalidInput,
246
247 #[error(transparent)]
249 EmptyInput(#[from] EmptyInputError),
250
251 #[error(transparent)]
253 GroupStateError(#[from] MlsGroupStateError),
254
255 #[error(transparent)]
257 LibraryError(#[from] LibraryError),
258
259 #[error("The member that should be removed can not be found.")]
261 UnknownMember,
262
263 #[error("Error writing to storage: {0}")]
265 StorageError(StorageError),
266
267 #[error(transparent)]
269 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
270
271 #[error(transparent)]
273 CreateCommitError(#[from] CreateCommitError),
274}
275
276#[derive(Error, Debug, PartialEq, Clone)]
278pub enum ProposeAddMemberError<StorageError> {
279 #[error(transparent)]
281 LibraryError(#[from] LibraryError),
282 #[error("The new member does not support all required extensions.")]
284 UnsupportedExtensions,
285 #[error(transparent)]
287 GroupStateError(#[from] MlsGroupStateError),
288 #[error(transparent)]
290 LeafNodeValidation(#[from] LeafNodeValidationError),
291 #[error("Error writing to storage: {0}")]
293 StorageError(StorageError),
294}
295
296#[derive(Error, Debug, PartialEq, Clone)]
298pub enum ProposeRemoveMemberError<StorageError> {
299 #[error(transparent)]
301 LibraryError(#[from] LibraryError),
302 #[error(transparent)]
304 GroupStateError(#[from] MlsGroupStateError),
305 #[error("The member that should be removed can not be found.")]
307 UnknownMember,
308 #[error("Error writing to storage: {0}")]
310 StorageError(StorageError),
311}
312
313#[derive(Error, Debug, PartialEq, Clone)]
315pub enum RemoveMembersError<StorageError> {
316 #[error(transparent)]
318 LibraryError(#[from] LibraryError),
319 #[error(transparent)]
321 EmptyInput(#[from] EmptyInputError),
322 #[error(transparent)]
324 CreateCommitError(#[from] CreateCommitError),
325 #[error(transparent)]
327 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
328 #[error(transparent)]
330 GroupStateError(#[from] MlsGroupStateError),
331 #[error("The member that should be removed can not be found.")]
333 UnknownMember,
334 #[error("Error writing to storage: {0}")]
336 StorageError(StorageError),
337}
338
339#[derive(Error, Debug, PartialEq, Clone)]
341pub enum LeaveGroupError<StorageError> {
342 #[error(transparent)]
344 LibraryError(#[from] LibraryError),
345 #[error(transparent)]
347 GroupStateError(#[from] MlsGroupStateError),
348 #[error("An error ocurred while writing to storage")]
350 StorageError(StorageError),
351 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
353 CannotSelfRemoveWithPureCiphertext,
354}
355
356#[derive(Error, Debug, PartialEq, Clone)]
358pub enum SelfUpdateError<StorageError> {
359 #[error(transparent)]
361 LibraryError(#[from] LibraryError),
362 #[error(transparent)]
364 CreateCommitError(#[from] CreateCommitError),
365 #[error(transparent)]
367 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
368 #[error(transparent)]
370 GroupStateError(#[from] MlsGroupStateError),
371 #[error("Error accessing the storage.")]
373 StorageError(StorageError),
374 #[cfg(feature = "virtual-clients-draft")]
376 #[error(transparent)]
377 VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
378}
379
380#[derive(Error, Debug, PartialEq, Clone)]
382pub enum ProposeSelfUpdateError<StorageError> {
383 #[error(transparent)]
385 LibraryError(#[from] LibraryError),
386
387 #[error(transparent)]
389 GroupStateError(#[from] MlsGroupStateError),
390 #[error("Error accessing storage.")]
392 StorageError(StorageError),
393 #[error(transparent)]
395 PublicTreeError(#[from] PublicTreeError),
396 #[error(transparent)]
398 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
399 #[error("The updated leaf node does not support all group context extensions.")]
401 UnsupportedGroupContextExtensions,
402 #[error("Mismatched credential_with_key between leaf_node_parameters and new_signer")]
405 InvalidLeafNodeParameters,
406 #[error("Mismatched ciphersuite between new_signer and the group")]
409 InvalidSignerCiphersuite,
410}
411
412#[derive(Error, Debug, PartialEq, Clone)]
414pub enum CommitToPendingProposalsError<StorageError> {
415 #[error(transparent)]
417 LibraryError(#[from] LibraryError),
418 #[error(transparent)]
420 CreateCommitError(#[from] CreateCommitError),
421 #[error(transparent)]
423 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
424 #[error(transparent)]
426 GroupStateError(#[from] MlsGroupStateError),
427 #[error("Error writing to storage: {0}")]
429 StorageError(StorageError),
430}
431
432#[derive(Error, Debug, PartialEq, Clone)]
434pub enum ExportGroupInfoError {
435 #[error(transparent)]
437 LibraryError(#[from] LibraryError),
438 #[error(transparent)]
440 GroupStateError(#[from] MlsGroupStateError),
441 #[error(transparent)]
443 InvalidExtensionError(#[from] InvalidExtensionError),
444}
445
446#[cfg(feature = "extensions-draft")]
448#[derive(Error, Debug, PartialEq, Clone)]
449pub enum SafeExportSecretError<StorageError> {
450 #[error(transparent)]
452 GroupState(#[from] MlsGroupStateError),
453 #[error(transparent)]
455 ApplicationExportTree(#[from] ApplicationExportTreeError),
456 #[error("Group doesn't support application exports.")]
458 Unsupported,
459 #[error("Error accessing storage: {0}")]
461 Storage(StorageError),
462}
463
464#[cfg(feature = "extensions-draft")]
466#[derive(Error, Debug, PartialEq, Clone)]
467pub enum ResolveAppDataCommitError {
468 #[error("The processed message does not carry an unresolved app data commit.")]
470 NotAnUnresolvedAppDataCommit,
471 #[error(transparent)]
473 StageCommit(#[from] StageCommitError),
474}
475
476#[cfg(feature = "extensions-draft")]
478#[derive(Error, Debug, PartialEq, Clone)]
479pub enum ProcessedMessageSafeExportSecretError {
480 #[error(transparent)]
482 SafeExportSecretError(#[from] StagedSafeExportSecretError),
483 #[error("Processed message is not a commit.")]
485 NotACommit,
486}
487
488#[cfg(feature = "extensions-draft")]
490#[derive(Error, Debug, PartialEq, Clone)]
491pub enum PendingSafeExportSecretError<StorageError> {
492 #[error(transparent)]
494 SafeExportSecretError(#[from] StagedSafeExportSecretError),
495 #[error("No pending commit.")]
497 NoPendingCommit,
498 #[error("Error accessing storage: {0}")]
500 Storage(StorageError),
501 #[error("Only group members can export secrets.")]
503 NotGroupMember,
504}
505
506#[cfg(feature = "extensions-draft")]
508#[derive(Error, Debug, PartialEq, Clone)]
509pub enum StagedSafeExportSecretError {
510 #[error("Only group members can export secrets.")]
512 NotGroupMember,
513 #[error(transparent)]
515 ApplicationExportTree(#[from] ApplicationExportTreeError),
516 #[error("Group doesn't support application exports.")]
518 Unsupported,
519}
520
521#[derive(Error, Debug, PartialEq, Clone)]
523pub enum ExportSecretError {
524 #[error(transparent)]
526 LibraryError(#[from] LibraryError),
527 #[error("The requested key length is too long.")]
529 KeyLengthTooLong,
530 #[error(transparent)]
532 GroupStateError(#[from] MlsGroupStateError),
533}
534
535#[derive(Error, Debug, PartialEq, Clone)]
537pub enum ProposePskError {
538 #[error(transparent)]
540 Psk(#[from] PskError),
541 #[error(transparent)]
543 GroupStateError(#[from] MlsGroupStateError),
544 #[error(transparent)]
546 LibraryError(#[from] LibraryError),
547}
548
549#[derive(Error, Debug, PartialEq, Clone)]
551pub enum ProposalError<StorageError> {
552 #[error(transparent)]
554 LibraryError(#[from] LibraryError),
555 #[error(transparent)]
557 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
558 #[error(transparent)]
560 CreateAddProposalError(#[from] CreateAddProposalError),
561 #[error(transparent)]
563 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
564 #[error(transparent)]
566 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
567 #[error(transparent)]
569 GroupStateError(#[from] MlsGroupStateError),
570 #[error(transparent)]
572 ValidationError(#[from] ValidationError),
573 #[error(transparent)]
575 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
576 #[error(transparent)]
578 InvalidExtension(#[from] InvalidExtensionError),
579 #[error("error writing proposal to storage")]
581 StorageError(StorageError),
582}
583
584#[derive(Error, Debug, PartialEq, Clone)]
586pub enum RemoveProposalError<StorageError> {
587 #[error("Couldn't find the proposal for the given `ProposalRef`")]
589 ProposalNotFound,
590 #[error("error writing proposal to storage")]
592 Storage(StorageError),
593}
594
595#[cfg(feature = "virtual-clients-draft")]
596pub use virtual_clients_draft::*;
597
598#[cfg(feature = "virtual-clients-draft")]
599mod virtual_clients_draft {
600 use thiserror::Error;
601
602 use super::MlsGroupStateError;
603 use crate::error::LibraryError;
604 use crate::framing::MessageEncryptionError;
605 use crate::tree::secret_tree::SecretTreeError;
606
607 #[derive(Error, Debug, PartialEq, Clone)]
609 pub enum CreateMessageError<StorageError> {
610 #[error(transparent)]
612 LibraryError(#[from] LibraryError),
613 #[error(transparent)]
615 GroupStateError(#[from] MlsGroupStateError),
616 #[error(transparent)]
618 MessageEncryptionError(#[from] MessageEncryptionError<StorageError>),
619 #[error("Error writing to storage: {0}")]
621 StorageError(StorageError),
622 }
623
624 #[derive(Error, Debug, PartialEq, Clone)]
626 pub enum ConfirmMessageError<StorageError> {
627 #[error(transparent)]
629 SecretTreeError(#[from] SecretTreeError),
630 #[error("The requested epoch is newer than the group's current epoch.")]
632 FutureEpoch,
633 #[error("Error writing to storage: {0}")]
635 StorageError(StorageError),
636 }
637
638 impl<StorageError> From<ConfirmMessageError<StorageError>> for CreateMessageError<StorageError> {
639 fn from(err: ConfirmMessageError<StorageError>) -> Self {
640 match err {
641 ConfirmMessageError::SecretTreeError(e) => {
642 CreateMessageError::MessageEncryptionError(
643 MessageEncryptionError::SecretTreeError(e),
644 )
645 }
646 ConfirmMessageError::FutureEpoch => CreateMessageError::LibraryError(
649 LibraryError::custom("confirm_application_message reported a future epoch"),
650 ),
651 ConfirmMessageError::StorageError(e) => CreateMessageError::StorageError(e),
652 }
653 }
654 }
655
656 #[derive(Error, Debug, PartialEq, Clone)]
663 pub enum RegisterVcDerivationEpochError<StorageError> {
664 #[error(transparent)]
669 ApplicationExportTree(#[from] super::ApplicationExportTreeError),
670 #[error(
675 "The emulation group has no application export tree to source the derivation epoch \
676 from."
677 )]
678 MissingApplicationExportTree,
679 #[error(transparent)]
682 VirtualClients(#[from] crate::components::vc_derivation_info::VirtualClientsError),
683 #[error("Error writing virtual-clients state to storage")]
685 Storage(StorageError),
686 }
687}