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 #[cfg(feature = "virtual-clients-draft")]
63 #[error(transparent)]
64 VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
65 #[cfg(feature = "virtual-clients-draft")]
68 #[error(transparent)]
69 RegisterVcDerivationEpoch(#[from] RegisterVcDerivationEpochError<StorageError>),
70}
71
72#[derive(Error, Debug, PartialEq, Eq, Clone)]
74pub enum DeletePastEpochSecretsError<StorageError> {
75 #[error(transparent)]
77 StorageError(#[from] StorageError),
78}
79
80#[derive(Error, Debug, PartialEq, Eq, Clone)]
82pub enum SetPastEpochDeletionPolicyError<StorageError> {
83 #[error(transparent)]
85 StorageError(#[from] StorageError),
86}
87
88#[derive(Error, Debug, PartialEq, Eq, Clone)]
90pub enum EmptyInputError {
91 #[error("An empty list of KeyPackages was provided.")]
93 AddMembers,
94 #[error("An empty list of KeyPackage references was provided.")]
96 RemoveMembers,
97}
98
99#[derive(Error, Debug, PartialEq, Clone)]
101pub enum MlsGroupStateError {
102 #[error(transparent)]
104 LibraryError(#[from] LibraryError),
105 #[error("Tried to use a group after being evicted from it.")]
107 UseAfterEviction,
108 #[error("Can't create message because a pending proposal exists.")]
110 PendingProposal,
111 #[error("Can't execute operation because a pending commit exists.")]
113 PendingCommit,
114 #[error("Can't execute operation because there is no pending commit")]
116 NoPendingCommit,
117 #[error("Requested pending proposal hasn't been found in local pending proposals.")]
119 PendingProposalNotFound,
120}
121
122#[derive(Error, Debug, PartialEq, Clone)]
124pub enum MergePendingCommitError<StorageError> {
125 #[error(transparent)]
127 MlsGroupStateError(#[from] MlsGroupStateError),
128 #[error(transparent)]
130 MergeCommitError(#[from] MergeCommitError<StorageError>),
131}
132
133#[derive(Error, Debug, PartialEq, Clone)]
135pub enum PublicProcessMessageError {
136 #[error(transparent)]
138 LibraryError(#[from] LibraryError),
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 InvalidCommit(#[from] StageCommitError),
148 #[error("External application messages are not permitted.")]
150 UnauthorizedExternalApplicationMessage,
151 #[error("Commit messages from external senders are not permitted.")]
153 UnauthorizedExternalCommitMessage,
154 #[error("The proposal is invalid for the Sender of type External")]
156 UnsupportedProposalType,
157
158 #[cfg(feature = "extensions-draft")]
161 #[error("malformed SafeAAD prefix in authenticated_data")]
162 MalformedSafeAad,
163}
164
165#[derive(Error, Debug, PartialEq, Clone)]
167pub enum ProcessMessageError<StorageError> {
168 #[error(transparent)]
170 LibraryError(#[from] LibraryError),
171 #[error("Error writing to storage: {0}")]
173 StorageError(StorageError),
174 #[error("The message's wire format is incompatible with the group's wire format policy.")]
176 IncompatibleWireFormat,
177 #[error(transparent)]
179 ValidationError(#[from] ValidationError),
180 #[error(transparent)]
182 GroupStateError(#[from] MlsGroupStateError),
183 #[error(transparent)]
185 InvalidCommit(#[from] StageCommitError),
186 #[error("External application messages are not permitted.")]
188 UnauthorizedExternalApplicationMessage,
189 #[error("Commit messages from external senders are not permitted.")]
191 UnauthorizedExternalCommitMessage,
192 #[error("The proposal is invalid for the Sender of type External")]
194 UnsupportedProposalType,
195 #[cfg(feature = "extensions-draft")]
198 #[error("malformed SafeAAD prefix in authenticated_data")]
199 MalformedSafeAad,
200}
201
202#[cfg(not(feature = "virtual-clients-draft"))]
204#[derive(Error, Debug, PartialEq, Clone)]
205pub enum CreateMessageError {
206 #[error(transparent)]
208 LibraryError(#[from] LibraryError),
209 #[error(transparent)]
211 GroupStateError(#[from] MlsGroupStateError),
212}
213
214#[derive(Error, Debug, PartialEq, Clone)]
216pub enum AddMembersError<StorageError> {
217 #[error(transparent)]
219 LibraryError(#[from] LibraryError),
220 #[error(transparent)]
222 EmptyInput(#[from] EmptyInputError),
223 #[error(transparent)]
225 CreateCommitError(#[from] CreateCommitError),
226 #[error(transparent)]
228 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
229 #[error(transparent)]
231 GroupStateError(#[from] MlsGroupStateError),
232 #[error("Error writing to storage")]
234 StorageError(StorageError),
235}
236
237#[derive(Error, Debug, PartialEq, Clone)]
239pub enum SwapMembersError<StorageError> {
240 #[error("Number of added and removed members is not the same")]
242 InvalidInput,
243
244 #[error(transparent)]
246 EmptyInput(#[from] EmptyInputError),
247
248 #[error(transparent)]
250 GroupStateError(#[from] MlsGroupStateError),
251
252 #[error(transparent)]
254 LibraryError(#[from] LibraryError),
255
256 #[error("The member that should be removed can not be found.")]
258 UnknownMember,
259
260 #[error("Error writing to storage: {0}")]
262 StorageError(StorageError),
263
264 #[error(transparent)]
266 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
267
268 #[error(transparent)]
270 CreateCommitError(#[from] CreateCommitError),
271}
272
273#[derive(Error, Debug, PartialEq, Clone)]
275pub enum ProposeAddMemberError<StorageError> {
276 #[error(transparent)]
278 LibraryError(#[from] LibraryError),
279 #[error("The new member does not support all required extensions.")]
281 UnsupportedExtensions,
282 #[error(transparent)]
284 GroupStateError(#[from] MlsGroupStateError),
285 #[error(transparent)]
287 LeafNodeValidation(#[from] LeafNodeValidationError),
288 #[error("Error writing to storage: {0}")]
290 StorageError(StorageError),
291}
292
293#[derive(Error, Debug, PartialEq, Clone)]
295pub enum ProposeRemoveMemberError<StorageError> {
296 #[error(transparent)]
298 LibraryError(#[from] LibraryError),
299 #[error(transparent)]
301 GroupStateError(#[from] MlsGroupStateError),
302 #[error("The member that should be removed can not be found.")]
304 UnknownMember,
305 #[error("Error writing to storage: {0}")]
307 StorageError(StorageError),
308}
309
310#[derive(Error, Debug, PartialEq, Clone)]
312pub enum RemoveMembersError<StorageError> {
313 #[error(transparent)]
315 LibraryError(#[from] LibraryError),
316 #[error(transparent)]
318 EmptyInput(#[from] EmptyInputError),
319 #[error(transparent)]
321 CreateCommitError(#[from] CreateCommitError),
322 #[error(transparent)]
324 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
325 #[error(transparent)]
327 GroupStateError(#[from] MlsGroupStateError),
328 #[error("The member that should be removed can not be found.")]
330 UnknownMember,
331 #[error("Error writing to storage: {0}")]
333 StorageError(StorageError),
334}
335
336#[derive(Error, Debug, PartialEq, Clone)]
338pub enum LeaveGroupError<StorageError> {
339 #[error(transparent)]
341 LibraryError(#[from] LibraryError),
342 #[error(transparent)]
344 GroupStateError(#[from] MlsGroupStateError),
345 #[error("An error ocurred while writing to storage")]
347 StorageError(StorageError),
348 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
350 CannotSelfRemoveWithPureCiphertext,
351}
352
353#[derive(Error, Debug, PartialEq, Clone)]
355pub enum SelfUpdateError<StorageError> {
356 #[error(transparent)]
358 LibraryError(#[from] LibraryError),
359 #[error(transparent)]
361 CreateCommitError(#[from] CreateCommitError),
362 #[error(transparent)]
364 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
365 #[error(transparent)]
367 GroupStateError(#[from] MlsGroupStateError),
368 #[error("Error accessing the storage.")]
370 StorageError(StorageError),
371 #[cfg(feature = "virtual-clients-draft")]
373 #[error(transparent)]
374 VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
375}
376
377#[derive(Error, Debug, PartialEq, Clone)]
379pub enum ProposeSelfUpdateError<StorageError> {
380 #[error(transparent)]
382 LibraryError(#[from] LibraryError),
383
384 #[error(transparent)]
386 GroupStateError(#[from] MlsGroupStateError),
387 #[error("Error accessing storage.")]
389 StorageError(StorageError),
390 #[error(transparent)]
392 PublicTreeError(#[from] PublicTreeError),
393 #[error(transparent)]
395 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
396 #[error("The updated leaf node does not support all group context extensions.")]
398 UnsupportedGroupContextExtensions,
399 #[error("Mismatched credential_with_key between leaf_node_parameters and new_signer")]
402 InvalidLeafNodeParameters,
403 #[error("Mismatched ciphersuite between new_signer and the group")]
406 InvalidSignerCiphersuite,
407}
408
409#[derive(Error, Debug, PartialEq, Clone)]
411pub enum CommitToPendingProposalsError<StorageError> {
412 #[error(transparent)]
414 LibraryError(#[from] LibraryError),
415 #[error(transparent)]
417 CreateCommitError(#[from] CreateCommitError),
418 #[error(transparent)]
420 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
421 #[error(transparent)]
423 GroupStateError(#[from] MlsGroupStateError),
424 #[error("Error writing to storage: {0}")]
426 StorageError(StorageError),
427}
428
429#[derive(Error, Debug, PartialEq, Clone)]
431pub enum ExportGroupInfoError {
432 #[error(transparent)]
434 LibraryError(#[from] LibraryError),
435 #[error(transparent)]
437 GroupStateError(#[from] MlsGroupStateError),
438 #[error(transparent)]
440 InvalidExtensionError(#[from] InvalidExtensionError),
441}
442
443#[cfg(feature = "extensions-draft")]
445#[derive(Error, Debug, PartialEq, Clone)]
446pub enum SafeExportSecretError<StorageError> {
447 #[error(transparent)]
449 GroupState(#[from] MlsGroupStateError),
450 #[error(transparent)]
452 ApplicationExportTree(#[from] ApplicationExportTreeError),
453 #[error("Group doesn't support application exports.")]
455 Unsupported,
456 #[error("Error accessing storage: {0}")]
458 Storage(StorageError),
459}
460
461#[cfg(feature = "extensions-draft")]
463#[derive(Error, Debug, PartialEq, Clone)]
464pub enum ResolveAppDataCommitError {
465 #[error("The processed message does not carry an unresolved app data commit.")]
467 NotAnUnresolvedAppDataCommit,
468 #[error(transparent)]
470 StageCommit(#[from] StageCommitError),
471}
472
473#[cfg(feature = "extensions-draft")]
475#[derive(Error, Debug, PartialEq, Clone)]
476pub enum ProcessedMessageSafeExportSecretError {
477 #[error(transparent)]
479 SafeExportSecretError(#[from] StagedSafeExportSecretError),
480 #[error("Processed message is not a commit.")]
482 NotACommit,
483}
484
485#[cfg(feature = "extensions-draft")]
487#[derive(Error, Debug, PartialEq, Clone)]
488pub enum PendingSafeExportSecretError<StorageError> {
489 #[error(transparent)]
491 SafeExportSecretError(#[from] StagedSafeExportSecretError),
492 #[error("No pending commit.")]
494 NoPendingCommit,
495 #[error("Error accessing storage: {0}")]
497 Storage(StorageError),
498 #[error("Only group members can export secrets.")]
500 NotGroupMember,
501}
502
503#[cfg(feature = "extensions-draft")]
505#[derive(Error, Debug, PartialEq, Clone)]
506pub enum StagedSafeExportSecretError {
507 #[error("Only group members can export secrets.")]
509 NotGroupMember,
510 #[error(transparent)]
512 ApplicationExportTree(#[from] ApplicationExportTreeError),
513 #[error("Group doesn't support application exports.")]
515 Unsupported,
516}
517
518#[derive(Error, Debug, PartialEq, Clone)]
520pub enum ExportSecretError {
521 #[error(transparent)]
523 LibraryError(#[from] LibraryError),
524 #[error("The requested key length is too long.")]
526 KeyLengthTooLong,
527 #[error(transparent)]
529 GroupStateError(#[from] MlsGroupStateError),
530}
531
532#[derive(Error, Debug, PartialEq, Clone)]
534pub enum ProposePskError {
535 #[error(transparent)]
537 Psk(#[from] PskError),
538 #[error(transparent)]
540 GroupStateError(#[from] MlsGroupStateError),
541 #[error(transparent)]
543 LibraryError(#[from] LibraryError),
544}
545
546#[derive(Error, Debug, PartialEq, Clone)]
548pub enum ProposalError<StorageError> {
549 #[error(transparent)]
551 LibraryError(#[from] LibraryError),
552 #[error(transparent)]
554 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
555 #[error(transparent)]
557 CreateAddProposalError(#[from] CreateAddProposalError),
558 #[error(transparent)]
560 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
561 #[error(transparent)]
563 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
564 #[error(transparent)]
566 GroupStateError(#[from] MlsGroupStateError),
567 #[error(transparent)]
569 ValidationError(#[from] ValidationError),
570 #[error(transparent)]
572 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
573 #[error(transparent)]
575 InvalidExtension(#[from] InvalidExtensionError),
576 #[error("error writing proposal to storage")]
578 StorageError(StorageError),
579}
580
581#[derive(Error, Debug, PartialEq, Clone)]
583pub enum RemoveProposalError<StorageError> {
584 #[error("Couldn't find the proposal for the given `ProposalRef`")]
586 ProposalNotFound,
587 #[error("error writing proposal to storage")]
589 Storage(StorageError),
590}
591
592#[cfg(feature = "virtual-clients-draft")]
593pub use virtual_clients_draft::*;
594
595#[cfg(feature = "virtual-clients-draft")]
596mod virtual_clients_draft {
597 use thiserror::Error;
598
599 use super::MlsGroupStateError;
600 use crate::error::LibraryError;
601 use crate::framing::MessageEncryptionError;
602 use crate::tree::secret_tree::SecretTreeError;
603
604 #[derive(Error, Debug, PartialEq, Clone)]
606 pub enum CreateMessageError<StorageError> {
607 #[error(transparent)]
609 LibraryError(#[from] LibraryError),
610 #[error(transparent)]
612 GroupStateError(#[from] MlsGroupStateError),
613 #[error(transparent)]
615 MessageEncryptionError(#[from] MessageEncryptionError<StorageError>),
616 #[error("Error writing to storage: {0}")]
618 StorageError(StorageError),
619 }
620
621 #[derive(Error, Debug, PartialEq, Clone)]
623 pub enum ConfirmMessageError<StorageError> {
624 #[error(transparent)]
626 SecretTreeError(#[from] SecretTreeError),
627 #[error("The requested epoch is newer than the group's current epoch.")]
629 FutureEpoch,
630 #[error("Error writing to storage: {0}")]
632 StorageError(StorageError),
633 }
634
635 impl<StorageError> From<ConfirmMessageError<StorageError>> for CreateMessageError<StorageError> {
636 fn from(err: ConfirmMessageError<StorageError>) -> Self {
637 match err {
638 ConfirmMessageError::SecretTreeError(e) => {
639 CreateMessageError::MessageEncryptionError(
640 MessageEncryptionError::SecretTreeError(e),
641 )
642 }
643 ConfirmMessageError::FutureEpoch => CreateMessageError::LibraryError(
646 LibraryError::custom("confirm_application_message reported a future epoch"),
647 ),
648 ConfirmMessageError::StorageError(e) => CreateMessageError::StorageError(e),
649 }
650 }
651 }
652
653 #[derive(Error, Debug, PartialEq, Clone)]
660 pub enum RegisterVcDerivationEpochError<StorageError> {
661 #[error(transparent)]
666 ApplicationExportTree(#[from] super::ApplicationExportTreeError),
667 #[error(
672 "The emulation group has no application export tree to source the derivation epoch \
673 from."
674 )]
675 MissingApplicationExportTree,
676 #[error(transparent)]
679 VirtualClients(#[from] crate::components::vc_derivation_info::VirtualClientsError),
680 #[error("Error writing virtual-clients state to storage")]
682 Storage(StorageError),
683 }
684}