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}
66
67#[derive(Error, Debug, PartialEq, Eq, Clone)]
69pub enum DeletePastEpochSecretsError<StorageError> {
70 #[error(transparent)]
72 StorageError(#[from] StorageError),
73}
74
75#[derive(Error, Debug, PartialEq, Eq, Clone)]
77pub enum SetPastEpochDeletionPolicyError<StorageError> {
78 #[error(transparent)]
80 StorageError(#[from] StorageError),
81}
82
83#[derive(Error, Debug, PartialEq, Eq, Clone)]
85pub enum EmptyInputError {
86 #[error("An empty list of KeyPackages was provided.")]
88 AddMembers,
89 #[error("An empty list of KeyPackage references was provided.")]
91 RemoveMembers,
92}
93
94#[derive(Error, Debug, PartialEq, Clone)]
96pub enum MlsGroupStateError {
97 #[error(transparent)]
99 LibraryError(#[from] LibraryError),
100 #[error("Tried to use a group after being evicted from it.")]
102 UseAfterEviction,
103 #[error("Can't create message because a pending proposal exists.")]
105 PendingProposal,
106 #[error("Can't execute operation because a pending commit exists.")]
108 PendingCommit,
109 #[error("Can't execute operation because there is no pending commit")]
111 NoPendingCommit,
112 #[error("Requested pending proposal hasn't been found in local pending proposals.")]
114 PendingProposalNotFound,
115}
116
117#[derive(Error, Debug, PartialEq, Clone)]
119pub enum MergePendingCommitError<StorageError> {
120 #[error(transparent)]
122 MlsGroupStateError(#[from] MlsGroupStateError),
123 #[error(transparent)]
125 MergeCommitError(#[from] MergeCommitError<StorageError>),
126}
127
128#[derive(Error, Debug, PartialEq, Clone)]
130pub enum PublicProcessMessageError {
131 #[error(transparent)]
133 LibraryError(#[from] LibraryError),
134 #[error("The message's wire format is incompatible with the group's wire format policy.")]
136 IncompatibleWireFormat,
137 #[error(transparent)]
139 ValidationError(#[from] ValidationError),
140 #[error(transparent)]
142 InvalidCommit(#[from] StageCommitError),
143 #[error("External application messages are not permitted.")]
145 UnauthorizedExternalApplicationMessage,
146 #[error("Commit messages from external senders are not permitted.")]
148 UnauthorizedExternalCommitMessage,
149 #[error("The proposal is invalid for the Sender of type External")]
151 UnsupportedProposalType,
152
153 #[cfg(feature = "extensions-draft")]
156 #[error("malformed SafeAAD prefix in authenticated_data")]
157 MalformedSafeAad,
158}
159
160#[derive(Error, Debug, PartialEq, Clone)]
162pub enum ProcessMessageError<StorageError> {
163 #[error(transparent)]
165 LibraryError(#[from] LibraryError),
166 #[error("Error writing to storage: {0}")]
168 StorageError(StorageError),
169 #[error("The message's wire format is incompatible with the group's wire format policy.")]
171 IncompatibleWireFormat,
172 #[error(transparent)]
174 ValidationError(#[from] ValidationError),
175 #[error(transparent)]
177 GroupStateError(#[from] MlsGroupStateError),
178 #[error(transparent)]
180 InvalidCommit(#[from] StageCommitError),
181 #[error("External application messages are not permitted.")]
183 UnauthorizedExternalApplicationMessage,
184 #[error("Commit messages from external senders are not permitted.")]
186 UnauthorizedExternalCommitMessage,
187 #[error("The proposal is invalid for the Sender of type External")]
189 UnsupportedProposalType,
190 #[cfg(feature = "extensions-draft")]
193 #[error("malformed SafeAAD prefix in authenticated_data")]
194 MalformedSafeAad,
195}
196
197#[cfg(not(feature = "virtual-clients-draft"))]
199#[derive(Error, Debug, PartialEq, Clone)]
200pub enum CreateMessageError {
201 #[error(transparent)]
203 LibraryError(#[from] LibraryError),
204 #[error(transparent)]
206 GroupStateError(#[from] MlsGroupStateError),
207}
208
209#[derive(Error, Debug, PartialEq, Clone)]
211pub enum AddMembersError<StorageError> {
212 #[error(transparent)]
214 LibraryError(#[from] LibraryError),
215 #[error(transparent)]
217 EmptyInput(#[from] EmptyInputError),
218 #[error(transparent)]
220 CreateCommitError(#[from] CreateCommitError),
221 #[error(transparent)]
223 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
224 #[error(transparent)]
226 GroupStateError(#[from] MlsGroupStateError),
227 #[error("Error writing to storage")]
229 StorageError(StorageError),
230}
231
232#[derive(Error, Debug, PartialEq, Clone)]
234pub enum SwapMembersError<StorageError> {
235 #[error("Number of added and removed members is not the same")]
237 InvalidInput,
238
239 #[error(transparent)]
241 EmptyInput(#[from] EmptyInputError),
242
243 #[error(transparent)]
245 GroupStateError(#[from] MlsGroupStateError),
246
247 #[error(transparent)]
249 LibraryError(#[from] LibraryError),
250
251 #[error("The member that should be removed can not be found.")]
253 UnknownMember,
254
255 #[error("Error writing to storage: {0}")]
257 StorageError(StorageError),
258
259 #[error(transparent)]
261 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
262
263 #[error(transparent)]
265 CreateCommitError(#[from] CreateCommitError),
266}
267
268#[derive(Error, Debug, PartialEq, Clone)]
270pub enum ProposeAddMemberError<StorageError> {
271 #[error(transparent)]
273 LibraryError(#[from] LibraryError),
274 #[error("The new member does not support all required extensions.")]
276 UnsupportedExtensions,
277 #[error(transparent)]
279 GroupStateError(#[from] MlsGroupStateError),
280 #[error(transparent)]
282 LeafNodeValidation(#[from] LeafNodeValidationError),
283 #[error("Error writing to storage: {0}")]
285 StorageError(StorageError),
286}
287
288#[derive(Error, Debug, PartialEq, Clone)]
290pub enum ProposeRemoveMemberError<StorageError> {
291 #[error(transparent)]
293 LibraryError(#[from] LibraryError),
294 #[error(transparent)]
296 GroupStateError(#[from] MlsGroupStateError),
297 #[error("The member that should be removed can not be found.")]
299 UnknownMember,
300 #[error("Error writing to storage: {0}")]
302 StorageError(StorageError),
303}
304
305#[derive(Error, Debug, PartialEq, Clone)]
307pub enum RemoveMembersError<StorageError> {
308 #[error(transparent)]
310 LibraryError(#[from] LibraryError),
311 #[error(transparent)]
313 EmptyInput(#[from] EmptyInputError),
314 #[error(transparent)]
316 CreateCommitError(#[from] CreateCommitError),
317 #[error(transparent)]
319 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
320 #[error(transparent)]
322 GroupStateError(#[from] MlsGroupStateError),
323 #[error("The member that should be removed can not be found.")]
325 UnknownMember,
326 #[error("Error writing to storage: {0}")]
328 StorageError(StorageError),
329}
330
331#[derive(Error, Debug, PartialEq, Clone)]
333pub enum LeaveGroupError<StorageError> {
334 #[error(transparent)]
336 LibraryError(#[from] LibraryError),
337 #[error(transparent)]
339 GroupStateError(#[from] MlsGroupStateError),
340 #[error("An error ocurred while writing to storage")]
342 StorageError(StorageError),
343 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
345 CannotSelfRemoveWithPureCiphertext,
346}
347
348#[derive(Error, Debug, PartialEq, Clone)]
350pub enum SelfUpdateError<StorageError> {
351 #[error(transparent)]
353 LibraryError(#[from] LibraryError),
354 #[error(transparent)]
356 CreateCommitError(#[from] CreateCommitError),
357 #[error(transparent)]
359 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
360 #[error(transparent)]
362 GroupStateError(#[from] MlsGroupStateError),
363 #[error("Error accessing the storage.")]
365 StorageError(StorageError),
366 #[cfg(feature = "virtual-clients-draft")]
368 #[error(transparent)]
369 VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
370}
371
372#[derive(Error, Debug, PartialEq, Clone)]
374pub enum ProposeSelfUpdateError<StorageError> {
375 #[error(transparent)]
377 LibraryError(#[from] LibraryError),
378
379 #[error(transparent)]
381 GroupStateError(#[from] MlsGroupStateError),
382 #[error("Error accessing storage.")]
384 StorageError(StorageError),
385 #[error(transparent)]
387 PublicTreeError(#[from] PublicTreeError),
388 #[error(transparent)]
390 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
391 #[error("The updated leaf node does not support all group context extensions.")]
393 UnsupportedGroupContextExtensions,
394 #[error("Mismatched credential_with_key between leaf_node_parameters and new_signer")]
397 InvalidLeafNodeParameters,
398 #[error("Mismatched ciphersuite between new_signer and the group")]
401 InvalidSignerCiphersuite,
402}
403
404#[derive(Error, Debug, PartialEq, Clone)]
406pub enum CommitToPendingProposalsError<StorageError> {
407 #[error(transparent)]
409 LibraryError(#[from] LibraryError),
410 #[error(transparent)]
412 CreateCommitError(#[from] CreateCommitError),
413 #[error(transparent)]
415 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
416 #[error(transparent)]
418 GroupStateError(#[from] MlsGroupStateError),
419 #[error("Error writing to storage: {0}")]
421 StorageError(StorageError),
422}
423
424#[derive(Error, Debug, PartialEq, Clone)]
426pub enum ExportGroupInfoError {
427 #[error(transparent)]
429 LibraryError(#[from] LibraryError),
430 #[error(transparent)]
432 GroupStateError(#[from] MlsGroupStateError),
433 #[error(transparent)]
435 InvalidExtensionError(#[from] InvalidExtensionError),
436}
437
438#[cfg(feature = "extensions-draft")]
440#[derive(Error, Debug, PartialEq, Clone)]
441pub enum SafeExportSecretError<StorageError> {
442 #[error(transparent)]
444 GroupState(#[from] MlsGroupStateError),
445 #[error(transparent)]
447 ApplicationExportTree(#[from] ApplicationExportTreeError),
448 #[error("Group doesn't support application exports.")]
450 Unsupported,
451 #[error("Error accessing storage: {0}")]
453 Storage(StorageError),
454}
455
456#[cfg(feature = "extensions-draft")]
458#[derive(Error, Debug, PartialEq, Clone)]
459pub enum ResolveAppDataCommitError {
460 #[error("The processed message does not carry an unresolved app data commit.")]
462 NotAnUnresolvedAppDataCommit,
463 #[error(transparent)]
465 StageCommit(#[from] StageCommitError),
466}
467
468#[cfg(feature = "extensions-draft")]
470#[derive(Error, Debug, PartialEq, Clone)]
471pub enum ProcessedMessageSafeExportSecretError {
472 #[error(transparent)]
474 SafeExportSecretError(#[from] StagedSafeExportSecretError),
475 #[error("Processed message is not a commit.")]
477 NotACommit,
478}
479
480#[cfg(feature = "extensions-draft")]
482#[derive(Error, Debug, PartialEq, Clone)]
483pub enum PendingSafeExportSecretError<StorageError> {
484 #[error(transparent)]
486 SafeExportSecretError(#[from] StagedSafeExportSecretError),
487 #[error("No pending commit.")]
489 NoPendingCommit,
490 #[error("Error accessing storage: {0}")]
492 Storage(StorageError),
493 #[error("Only group members can export secrets.")]
495 NotGroupMember,
496}
497
498#[cfg(feature = "extensions-draft")]
500#[derive(Error, Debug, PartialEq, Clone)]
501pub enum StagedSafeExportSecretError {
502 #[error("Only group members can export secrets.")]
504 NotGroupMember,
505 #[error(transparent)]
507 ApplicationExportTree(#[from] ApplicationExportTreeError),
508 #[error("Group doesn't support application exports.")]
510 Unsupported,
511}
512
513#[derive(Error, Debug, PartialEq, Clone)]
515pub enum ExportSecretError {
516 #[error(transparent)]
518 LibraryError(#[from] LibraryError),
519 #[error("The requested key length is too long.")]
521 KeyLengthTooLong,
522 #[error(transparent)]
524 GroupStateError(#[from] MlsGroupStateError),
525}
526
527#[derive(Error, Debug, PartialEq, Clone)]
529pub enum ProposePskError {
530 #[error(transparent)]
532 Psk(#[from] PskError),
533 #[error(transparent)]
535 GroupStateError(#[from] MlsGroupStateError),
536 #[error(transparent)]
538 LibraryError(#[from] LibraryError),
539}
540
541#[derive(Error, Debug, PartialEq, Clone)]
543pub enum ProposalError<StorageError> {
544 #[error(transparent)]
546 LibraryError(#[from] LibraryError),
547 #[error(transparent)]
549 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
550 #[error(transparent)]
552 CreateAddProposalError(#[from] CreateAddProposalError),
553 #[error(transparent)]
555 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
556 #[error(transparent)]
558 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
559 #[error(transparent)]
561 GroupStateError(#[from] MlsGroupStateError),
562 #[error(transparent)]
564 ValidationError(#[from] ValidationError),
565 #[error(transparent)]
567 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
568 #[error(transparent)]
570 InvalidExtension(#[from] InvalidExtensionError),
571 #[error("error writing proposal to storage")]
573 StorageError(StorageError),
574}
575
576#[derive(Error, Debug, PartialEq, Clone)]
578pub enum RemoveProposalError<StorageError> {
579 #[error("Couldn't find the proposal for the given `ProposalRef`")]
581 ProposalNotFound,
582 #[error("error writing proposal to storage")]
584 Storage(StorageError),
585}
586
587#[cfg(feature = "virtual-clients-draft")]
588pub use virtual_clients_draft::*;
589
590#[cfg(feature = "virtual-clients-draft")]
591mod virtual_clients_draft {
592 use thiserror::Error;
593
594 use super::MlsGroupStateError;
595 use crate::error::LibraryError;
596 use crate::framing::MessageEncryptionError;
597 use crate::group::SafeExportSecretError;
598 use crate::tree::secret_tree::SecretTreeError;
599
600 #[derive(Error, Debug, PartialEq, Clone)]
602 pub enum CreateMessageError<StorageError> {
603 #[error(transparent)]
605 LibraryError(#[from] LibraryError),
606 #[error(transparent)]
608 GroupStateError(#[from] MlsGroupStateError),
609 #[error(transparent)]
611 MessageEncryptionError(#[from] MessageEncryptionError<StorageError>),
612 #[error("Error writing to storage: {0}")]
614 StorageError(StorageError),
615 }
616
617 #[derive(Error, Debug, PartialEq, Clone)]
619 pub enum ConfirmMessageError<StorageError> {
620 #[error(transparent)]
622 SecretTreeError(#[from] SecretTreeError),
623 #[error("The requested epoch is newer than the group's current epoch.")]
625 FutureEpoch,
626 #[error("Error writing to storage: {0}")]
628 StorageError(StorageError),
629 }
630
631 impl<StorageError> From<ConfirmMessageError<StorageError>> for CreateMessageError<StorageError> {
632 fn from(err: ConfirmMessageError<StorageError>) -> Self {
633 match err {
634 ConfirmMessageError::SecretTreeError(e) => {
635 CreateMessageError::MessageEncryptionError(
636 MessageEncryptionError::SecretTreeError(e),
637 )
638 }
639 ConfirmMessageError::FutureEpoch => CreateMessageError::LibraryError(
642 LibraryError::custom("confirm_application_message reported a future epoch"),
643 ),
644 ConfirmMessageError::StorageError(e) => CreateMessageError::StorageError(e),
645 }
646 }
647 }
648
649 #[derive(Error, Debug, PartialEq, Clone)]
652 pub enum RegisterVcEmulationEpochError<StorageError> {
653 #[error(transparent)]
655 SafeExportSecret(#[from] SafeExportSecretError<StorageError>),
656 #[error(transparent)]
659 VirtualClients(#[from] crate::components::vc_derivation_info::VirtualClientsError),
660 #[error("Error writing virtual-clients state to storage")]
662 Storage(StorageError),
663 }
664}