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")]
28use crate::schedule::application_export_tree::ApplicationExportTreeError;
29
30#[derive(Error, Debug, PartialEq, Clone)]
32pub enum NewGroupError<StorageError> {
33 #[error(transparent)]
35 LibraryError(#[from] LibraryError),
36 #[error("No matching KeyPackage was found in the key store.")]
38 NoMatchingKeyPackage,
39 #[error("Error accessing the storage.")]
41 StorageError(StorageError),
42 #[error("Unsupported proposal type in required capabilities.")]
44 UnsupportedProposalType,
45 #[error("Unsupported extension type in required capabilities.")]
47 UnsupportedExtensionType,
48 #[error("Invalid extensions set in configuration")]
50 InvalidExtensions(#[from] InvalidExtensionError),
51}
52
53#[derive(Error, Debug, PartialEq, Eq, Clone)]
55pub enum EmptyInputError {
56 #[error("An empty list of KeyPackages was provided.")]
58 AddMembers,
59 #[error("An empty list of KeyPackage references was provided.")]
61 RemoveMembers,
62}
63
64#[derive(Error, Debug, PartialEq, Clone)]
66pub enum MlsGroupStateError {
67 #[error(transparent)]
69 LibraryError(#[from] LibraryError),
70 #[error("Tried to use a group after being evicted from it.")]
72 UseAfterEviction,
73 #[error("Can't create message because a pending proposal exists.")]
75 PendingProposal,
76 #[error("Can't execute operation because a pending commit exists.")]
78 PendingCommit,
79 #[error("Can't execute operation because there is no pending commit")]
81 NoPendingCommit,
82 #[error("Requested pending proposal hasn't been found in local pending proposals.")]
84 PendingProposalNotFound,
85}
86
87#[derive(Error, Debug, PartialEq, Clone)]
89pub enum MergePendingCommitError<StorageError> {
90 #[error(transparent)]
92 MlsGroupStateError(#[from] MlsGroupStateError),
93 #[error(transparent)]
95 MergeCommitError(#[from] MergeCommitError<StorageError>),
96}
97
98#[derive(Error, Debug, PartialEq, Clone)]
100pub enum PublicProcessMessageError {
101 #[error(transparent)]
103 LibraryError(#[from] LibraryError),
104 #[error("The message's wire format is incompatible with the group's wire format policy.")]
106 IncompatibleWireFormat,
107 #[error(transparent)]
109 ValidationError(#[from] ValidationError),
110 #[error(transparent)]
112 InvalidCommit(#[from] StageCommitError),
113 #[error("External application messages are not permitted.")]
115 UnauthorizedExternalApplicationMessage,
116 #[error("Commit messages from external senders are not permitted.")]
118 UnauthorizedExternalCommitMessage,
119 #[error("The proposal is invalid for the Sender of type External")]
121 UnsupportedProposalType,
122}
123
124#[derive(Error, Debug, PartialEq, Clone)]
126pub enum ProcessMessageError<StorageError> {
127 #[error(transparent)]
129 LibraryError(#[from] LibraryError),
130 #[error("Error writing to storage: {0}")]
132 StorageError(StorageError),
133 #[error("The message's wire format is incompatible with the group's wire format policy.")]
135 IncompatibleWireFormat,
136 #[error(transparent)]
138 ValidationError(#[from] ValidationError),
139 #[error(transparent)]
141 GroupStateError(#[from] MlsGroupStateError),
142 #[error(transparent)]
144 InvalidCommit(#[from] StageCommitError),
145 #[error("External application messages are not permitted.")]
147 UnauthorizedExternalApplicationMessage,
148 #[error("Commit messages from external senders are not permitted.")]
150 UnauthorizedExternalCommitMessage,
151 #[error("The proposal is invalid for the Sender of type External")]
153 UnsupportedProposalType,
154}
155
156#[derive(Error, Debug, PartialEq, Clone)]
158pub enum CreateMessageError {
159 #[error(transparent)]
161 LibraryError(#[from] LibraryError),
162 #[error(transparent)]
164 GroupStateError(#[from] MlsGroupStateError),
165}
166
167#[derive(Error, Debug, PartialEq, Clone)]
169pub enum AddMembersError<StorageError> {
170 #[error(transparent)]
172 LibraryError(#[from] LibraryError),
173 #[error(transparent)]
175 EmptyInput(#[from] EmptyInputError),
176 #[error(transparent)]
178 CreateCommitError(#[from] CreateCommitError),
179 #[error(transparent)]
181 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
182 #[error(transparent)]
184 GroupStateError(#[from] MlsGroupStateError),
185 #[error("Error writing to storage")]
187 StorageError(StorageError),
188}
189
190#[derive(Error, Debug, PartialEq, Clone)]
192pub enum SwapMembersError<StorageError> {
193 #[error("Number of added and removed members is not the same")]
195 InvalidInput,
196
197 #[error(transparent)]
199 EmptyInput(#[from] EmptyInputError),
200
201 #[error(transparent)]
203 GroupStateError(#[from] MlsGroupStateError),
204
205 #[error(transparent)]
207 LibraryError(#[from] LibraryError),
208
209 #[error("The member that should be removed can not be found.")]
211 UnknownMember,
212
213 #[error("Error writing to storage: {0}")]
215 StorageError(StorageError),
216
217 #[error(transparent)]
219 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
220
221 #[error(transparent)]
223 CreateCommitError(#[from] CreateCommitError),
224}
225
226#[derive(Error, Debug, PartialEq, Clone)]
228pub enum ProposeAddMemberError<StorageError> {
229 #[error(transparent)]
231 LibraryError(#[from] LibraryError),
232 #[error("The new member does not support all required extensions.")]
234 UnsupportedExtensions,
235 #[error(transparent)]
237 GroupStateError(#[from] MlsGroupStateError),
238 #[error(transparent)]
240 LeafNodeValidation(#[from] LeafNodeValidationError),
241 #[error("Error writing to storage: {0}")]
243 StorageError(StorageError),
244}
245
246#[derive(Error, Debug, PartialEq, Clone)]
248pub enum ProposeRemoveMemberError<StorageError> {
249 #[error(transparent)]
251 LibraryError(#[from] LibraryError),
252 #[error(transparent)]
254 GroupStateError(#[from] MlsGroupStateError),
255 #[error("The member that should be removed can not be found.")]
257 UnknownMember,
258 #[error("Error writing to storage: {0}")]
260 StorageError(StorageError),
261}
262
263#[derive(Error, Debug, PartialEq, Clone)]
265pub enum RemoveMembersError<StorageError> {
266 #[error(transparent)]
268 LibraryError(#[from] LibraryError),
269 #[error(transparent)]
271 EmptyInput(#[from] EmptyInputError),
272 #[error(transparent)]
274 CreateCommitError(#[from] CreateCommitError),
275 #[error(transparent)]
277 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
278 #[error(transparent)]
280 GroupStateError(#[from] MlsGroupStateError),
281 #[error("The member that should be removed can not be found.")]
283 UnknownMember,
284 #[error("Error writing to storage: {0}")]
286 StorageError(StorageError),
287}
288
289#[derive(Error, Debug, PartialEq, Clone)]
291pub enum LeaveGroupError<StorageError> {
292 #[error(transparent)]
294 LibraryError(#[from] LibraryError),
295 #[error(transparent)]
297 GroupStateError(#[from] MlsGroupStateError),
298 #[error("An error ocurred while writing to storage")]
300 StorageError(StorageError),
301 #[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
303 CannotSelfRemoveWithPureCiphertext,
304}
305
306#[derive(Error, Debug, PartialEq, Clone)]
308pub enum SelfUpdateError<StorageError> {
309 #[error(transparent)]
311 LibraryError(#[from] LibraryError),
312 #[error(transparent)]
314 CreateCommitError(#[from] CreateCommitError),
315 #[error(transparent)]
317 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
318 #[error(transparent)]
320 GroupStateError(#[from] MlsGroupStateError),
321 #[error("Error accessing the storage.")]
323 StorageError(StorageError),
324}
325
326#[derive(Error, Debug, PartialEq, Clone)]
328pub enum ProposeSelfUpdateError<StorageError> {
329 #[error(transparent)]
331 LibraryError(#[from] LibraryError),
332
333 #[error(transparent)]
335 GroupStateError(#[from] MlsGroupStateError),
336 #[error("Error accessing storage.")]
338 StorageError(StorageError),
339 #[error(transparent)]
341 PublicTreeError(#[from] PublicTreeError),
342 #[error(transparent)]
344 LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
345}
346
347#[derive(Error, Debug, PartialEq, Clone)]
349pub enum CommitToPendingProposalsError<StorageError> {
350 #[error(transparent)]
352 LibraryError(#[from] LibraryError),
353 #[error(transparent)]
355 CreateCommitError(#[from] CreateCommitError),
356 #[error(transparent)]
358 CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
359 #[error(transparent)]
361 GroupStateError(#[from] MlsGroupStateError),
362 #[error("Error writing to storage: {0}")]
364 StorageError(StorageError),
365}
366
367#[derive(Error, Debug, PartialEq, Clone)]
369pub enum ExportGroupInfoError {
370 #[error(transparent)]
372 LibraryError(#[from] LibraryError),
373 #[error(transparent)]
375 GroupStateError(#[from] MlsGroupStateError),
376}
377
378#[cfg(feature = "extensions-draft-08")]
380#[derive(Error, Debug, PartialEq, Clone)]
381pub enum SafeExportSecretError<StorageError> {
382 #[error(transparent)]
384 GroupState(#[from] MlsGroupStateError),
385 #[error(transparent)]
387 ApplicationExportTree(#[from] ApplicationExportTreeError),
388 #[error("Group doesn't support application exports.")]
390 Unsupported,
391 #[error("Error accessing storage: {0}")]
393 Storage(StorageError),
394}
395
396#[cfg(feature = "extensions-draft-08")]
398#[derive(Error, Debug, PartialEq, Clone)]
399pub enum ProcessedMessageSafeExportSecretError {
400 #[error(transparent)]
402 SafeExportSecretError(#[from] StagedSafeExportSecretError),
403 #[error("Processed message is not a commit.")]
405 NotACommit,
406}
407
408#[cfg(feature = "extensions-draft-08")]
410#[derive(Error, Debug, PartialEq, Clone)]
411pub enum PendingSafeExportSecretError<StorageError> {
412 #[error(transparent)]
414 SafeExportSecretError(#[from] StagedSafeExportSecretError),
415 #[error("No pending commit.")]
417 NoPendingCommit,
418 #[error("Error accessing storage: {0}")]
420 Storage(StorageError),
421 #[error("Only group members can export secrets.")]
423 NotGroupMember,
424}
425
426#[cfg(feature = "extensions-draft-08")]
428#[derive(Error, Debug, PartialEq, Clone)]
429pub enum StagedSafeExportSecretError {
430 #[error("Only group members can export secrets.")]
432 NotGroupMember,
433 #[error(transparent)]
435 ApplicationExportTree(#[from] ApplicationExportTreeError),
436 #[error("Group doesn't support application exports.")]
438 Unsupported,
439}
440
441#[derive(Error, Debug, PartialEq, Clone)]
443pub enum ExportSecretError {
444 #[error(transparent)]
446 LibraryError(#[from] LibraryError),
447 #[error("The requested key length is too long.")]
449 KeyLengthTooLong,
450 #[error(transparent)]
452 GroupStateError(#[from] MlsGroupStateError),
453}
454
455#[derive(Error, Debug, PartialEq, Clone)]
457pub enum ProposePskError {
458 #[error(transparent)]
460 Psk(#[from] PskError),
461 #[error(transparent)]
463 GroupStateError(#[from] MlsGroupStateError),
464 #[error(transparent)]
466 LibraryError(#[from] LibraryError),
467}
468
469#[derive(Error, Debug, PartialEq, Clone)]
471pub enum ProposalError<StorageError> {
472 #[error(transparent)]
474 LibraryError(#[from] LibraryError),
475 #[error(transparent)]
477 ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
478 #[error(transparent)]
480 CreateAddProposalError(#[from] CreateAddProposalError),
481 #[error(transparent)]
483 ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
484 #[error(transparent)]
486 ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
487 #[error(transparent)]
489 GroupStateError(#[from] MlsGroupStateError),
490 #[error(transparent)]
492 ValidationError(#[from] ValidationError),
493 #[error(transparent)]
495 CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
496 #[error("error writing proposal to storage")]
498 StorageError(StorageError),
499}
500
501#[derive(Error, Debug, PartialEq, Clone)]
503pub enum RemoveProposalError<StorageError> {
504 #[error("Couldn't find the proposal for the given `ProposalRef`")]
506 ProposalNotFound,
507 #[error("error writing proposal to storage")]
509 Storage(StorageError),
510}