use thiserror::Error;
use crate::{
error::LibraryError,
extensions::errors::InvalidExtensionError,
group::{
errors::{
CreateAddProposalError, CreateCommitError, MergeCommitError, StageCommitError,
ValidationError,
},
CommitBuilderStageError, CreateGroupContextExtProposalError,
},
schedule::errors::PskError,
treesync::{
errors::{LeafNodeValidationError, PublicTreeError},
node::leaf_node::LeafNodeUpdateError,
},
};
#[cfg(feature = "extensions-draft-08")]
pub use crate::schedule::application_export_tree::ApplicationExportTreeError;
#[cfg(doc)]
use crate::group::GroupId;
#[derive(Error, Debug, PartialEq, Clone)]
pub enum NewGroupError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("No matching KeyPackage was found in the key store.")]
NoMatchingKeyPackage,
#[error("Error accessing the storage.")]
StorageError(StorageError),
#[error("Unsupported proposal type in required capabilities.")]
UnsupportedProposalType,
#[error("Unsupported extension type in required capabilities.")]
UnsupportedExtensionType,
#[error("Invalid extensions set in configuration")]
InvalidExtensions(#[from] InvalidExtensionError),
#[error("A group with the given GroupId already exists.")]
GroupAlreadyExists,
}
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum EmptyInputError {
#[error("An empty list of KeyPackages was provided.")]
AddMembers,
#[error("An empty list of KeyPackage references was provided.")]
RemoveMembers,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MlsGroupStateError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Tried to use a group after being evicted from it.")]
UseAfterEviction,
#[error("Can't create message because a pending proposal exists.")]
PendingProposal,
#[error("Can't execute operation because a pending commit exists.")]
PendingCommit,
#[error("Can't execute operation because there is no pending commit")]
NoPendingCommit,
#[error("Requested pending proposal hasn't been found in local pending proposals.")]
PendingProposalNotFound,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MergePendingCommitError<StorageError> {
#[error(transparent)]
MlsGroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
MergeCommitError(#[from] MergeCommitError<StorageError>),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum PublicProcessMessageError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The message's wire format is incompatible with the group's wire format policy.")]
IncompatibleWireFormat,
#[error(transparent)]
ValidationError(#[from] ValidationError),
#[error(transparent)]
InvalidCommit(#[from] StageCommitError),
#[error("External application messages are not permitted.")]
UnauthorizedExternalApplicationMessage,
#[error("Commit messages from external senders are not permitted.")]
UnauthorizedExternalCommitMessage,
#[error("The proposal is invalid for the Sender of type External")]
UnsupportedProposalType,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProcessMessageError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
#[error("The message's wire format is incompatible with the group's wire format policy.")]
IncompatibleWireFormat,
#[error(transparent)]
ValidationError(#[from] ValidationError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
InvalidCommit(#[from] StageCommitError),
#[error("External application messages are not permitted.")]
UnauthorizedExternalApplicationMessage,
#[error("Commit messages from external senders are not permitted.")]
UnauthorizedExternalCommitMessage,
#[error("The proposal is invalid for the Sender of type External")]
UnsupportedProposalType,
#[cfg(feature = "extensions-draft-08")]
#[error("Use `_with_app_data_update` functions for handling AppDataUpdate proposals")]
FoundAppDataUpdateProposal,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateMessageError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum AddMembersError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
EmptyInput(#[from] EmptyInputError),
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError),
#[error(transparent)]
CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("Error writing to storage")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum SwapMembersError<StorageError> {
#[error("Number of added and removed members is not the same")]
InvalidInput,
#[error(transparent)]
EmptyInput(#[from] EmptyInputError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The member that should be removed can not be found.")]
UnknownMember,
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
#[error(transparent)]
CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposeAddMemberError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The new member does not support all required extensions.")]
UnsupportedExtensions,
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposeRemoveMemberError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("The member that should be removed can not be found.")]
UnknownMember,
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum RemoveMembersError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
EmptyInput(#[from] EmptyInputError),
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError),
#[error(transparent)]
CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("The member that should be removed can not be found.")]
UnknownMember,
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum LeaveGroupError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("An error ocurred while writing to storage")]
StorageError(StorageError),
#[error("SelfRemove not allowed with pure ciphertext outgoing wire format policy.")]
CannotSelfRemoveWithPureCiphertext,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum SelfUpdateError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError),
#[error(transparent)]
CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("Error accessing the storage.")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposeSelfUpdateError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("Error accessing storage.")]
StorageError(StorageError),
#[error(transparent)]
PublicTreeError(#[from] PublicTreeError),
#[error(transparent)]
LeafNodeUpdateError(#[from] LeafNodeUpdateError<StorageError>),
#[error("The updated leaf node does not support all group context extensions.")]
UnsupportedGroupContextExtensions,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CommitToPendingProposalsError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError),
#[error(transparent)]
CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExportGroupInfoError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
InvalidExtensionError(#[from] InvalidExtensionError),
}
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum SafeExportSecretError<StorageError> {
#[error(transparent)]
GroupState(#[from] MlsGroupStateError),
#[error(transparent)]
ApplicationExportTree(#[from] ApplicationExportTreeError),
#[error("Group doesn't support application exports.")]
Unsupported,
#[error("Error accessing storage: {0}")]
Storage(StorageError),
}
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProcessedMessageSafeExportSecretError {
#[error(transparent)]
SafeExportSecretError(#[from] StagedSafeExportSecretError),
#[error("Processed message is not a commit.")]
NotACommit,
}
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum PendingSafeExportSecretError<StorageError> {
#[error(transparent)]
SafeExportSecretError(#[from] StagedSafeExportSecretError),
#[error("No pending commit.")]
NoPendingCommit,
#[error("Error accessing storage: {0}")]
Storage(StorageError),
#[error("Only group members can export secrets.")]
NotGroupMember,
}
#[cfg(feature = "extensions-draft-08")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum StagedSafeExportSecretError {
#[error("Only group members can export secrets.")]
NotGroupMember,
#[error(transparent)]
ApplicationExportTree(#[from] ApplicationExportTreeError),
#[error("Group doesn't support application exports.")]
Unsupported,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExportSecretError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The requested key length is too long.")]
KeyLengthTooLong,
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposePskError {
#[error(transparent)]
Psk(#[from] PskError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
LibraryError(#[from] LibraryError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposalError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
ProposeAddMemberError(#[from] ProposeAddMemberError<StorageError>),
#[error(transparent)]
CreateAddProposalError(#[from] CreateAddProposalError),
#[error(transparent)]
ProposeSelfUpdateError(#[from] ProposeSelfUpdateError<StorageError>),
#[error(transparent)]
ProposeRemoveMemberError(#[from] ProposeRemoveMemberError<StorageError>),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
ValidationError(#[from] ValidationError),
#[error(transparent)]
CreateGroupContextExtProposalError(#[from] CreateGroupContextExtProposalError<StorageError>),
#[error(transparent)]
InvalidExtension(#[from] InvalidExtensionError),
#[error("error writing proposal to storage")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum RemoveProposalError<StorageError> {
#[error("Couldn't find the proposal for the given `ProposalRef`")]
ProposalNotFound,
#[error("error writing proposal to storage")]
Storage(StorageError),
}