use openmls_traits::types::Ciphersuite;
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")]
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,
#[error("Ciphersuite {0:?} is not supported by the crypto provider.")]
UnsupportedCiphersuite(Ciphersuite),
#[cfg(feature = "virtual-clients-draft")]
#[error(transparent)]
VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
}
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum DeletePastEpochSecretsError<StorageError> {
#[error(transparent)]
StorageError(#[from] StorageError),
}
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum SetPastEpochDeletionPolicyError<StorageError> {
#[error(transparent)]
StorageError(#[from] StorageError),
}
#[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,
#[cfg(feature = "extensions-draft")]
#[error("malformed SafeAAD prefix in authenticated_data")]
MalformedSafeAad,
}
#[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")]
#[error("malformed SafeAAD prefix in authenticated_data")]
MalformedSafeAad,
}
#[cfg(not(feature = "virtual-clients-draft"))]
#[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),
#[cfg(feature = "virtual-clients-draft")]
#[error(transparent)]
VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
}
#[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,
#[error("Mismatched credential_with_key between leaf_node_parameters and new_signer")]
InvalidLeafNodeParameters,
#[error("Mismatched ciphersuite between new_signer and the group")]
InvalidSignerCiphersuite,
}
#[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")]
#[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")]
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ResolveAppDataCommitError {
#[error("The processed message does not carry an unresolved app data commit.")]
NotAnUnresolvedAppDataCommit,
#[error(transparent)]
StageCommit(#[from] StageCommitError),
}
#[cfg(feature = "extensions-draft")]
#[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")]
#[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")]
#[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),
}
#[cfg(feature = "virtual-clients-draft")]
pub use virtual_clients_draft::*;
#[cfg(feature = "virtual-clients-draft")]
mod virtual_clients_draft {
use thiserror::Error;
use super::MlsGroupStateError;
use crate::error::LibraryError;
use crate::framing::MessageEncryptionError;
use crate::group::SafeExportSecretError;
use crate::tree::secret_tree::SecretTreeError;
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateMessageError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
GroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
MessageEncryptionError(#[from] MessageEncryptionError<StorageError>),
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ConfirmMessageError<StorageError> {
#[error(transparent)]
SecretTreeError(#[from] SecretTreeError),
#[error("The requested epoch is newer than the group's current epoch.")]
FutureEpoch,
#[error("Error writing to storage: {0}")]
StorageError(StorageError),
}
impl<StorageError> From<ConfirmMessageError<StorageError>> for CreateMessageError<StorageError> {
fn from(err: ConfirmMessageError<StorageError>) -> Self {
match err {
ConfirmMessageError::SecretTreeError(e) => {
CreateMessageError::MessageEncryptionError(
MessageEncryptionError::SecretTreeError(e),
)
}
ConfirmMessageError::FutureEpoch => CreateMessageError::LibraryError(
LibraryError::custom("confirm_application_message reported a future epoch"),
),
ConfirmMessageError::StorageError(e) => CreateMessageError::StorageError(e),
}
}
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum RegisterVcEmulationEpochError<StorageError> {
#[error(transparent)]
SafeExportSecret(#[from] SafeExportSecretError<StorageError>),
#[error(transparent)]
VirtualClients(#[from] crate::components::vc_derivation_info::VirtualClientsError),
#[error("Error writing virtual-clients state to storage")]
Storage(StorageError),
}
}