use thiserror::Error;
pub use super::mls_group::errors::*;
use super::public_group::errors::CreationFromExternalError;
use crate::{
ciphersuite::signable::SignatureError,
error::LibraryError,
extensions::errors::{ExtensionError, InvalidExtensionError},
framing::errors::MessageDecryptionError,
key_packages::errors::{KeyPackageExtensionSupportError, KeyPackageVerifyError},
messages::{group_info::GroupInfoError, GroupSecretsError},
schedule::errors::PskError,
treesync::errors::*,
};
#[derive(Error, Debug, PartialEq, Clone)]
pub enum WelcomeError<StorageError> {
#[error(transparent)]
GroupSecrets(#[from] GroupSecretsError),
#[error("Private part of `init_key` not found in key store.")]
PrivateInitKeyNotFound,
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Ciphersuites in Welcome and key package bundle don't match.")]
CiphersuiteMismatch,
#[error(transparent)]
GroupInfo(#[from] GroupInfoError),
#[error("No joiner secret found in the Welcome message.")]
JoinerSecretNotFound,
#[error("No ratchet tree available to build initial tree after receiving a Welcome message.")]
MissingRatchetTree,
#[error("The computed confirmation tag does not match the expected one.")]
ConfirmationTagMismatch,
#[error("The signature on the GroupInfo is not valid.")]
InvalidGroupInfoSignature,
#[error("We don't support the version of the group we are trying to join.")]
UnsupportedMlsVersion,
#[error("We don't support all capabilities of the group.")]
UnsupportedCapability,
#[error("Sender not found in tree.")]
UnknownSender,
#[error("Not a Welcome message.")]
NotAWelcomeMessage,
#[error("Malformed Welcome message.")]
MalformedWelcomeMessage,
#[error("Could not decrypt the Welcome message.")]
UnableToDecrypt,
#[error("Unsupported extensions found in the KeyPackage of another member.")]
UnsupportedExtensions,
#[error(transparent)]
Psk(#[from] PskError),
#[error("No matching encryption key was found in the key store.")]
NoMatchingEncryptionKey,
#[error("No matching key package was found in the key store.")]
NoMatchingKeyPackage,
#[error(transparent)]
PublicTreeError(#[from] PublicTreeError),
#[error(transparent)]
PublicGroupError(#[from] CreationFromExternalError<StorageError>),
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
#[error("An error occurred when querying storage")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExternalCommitError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("No ratchet tree available to build initial tree.")]
MissingRatchetTree,
#[error("No external_pub extension available to join group by external commit.")]
MissingExternalPub,
#[error("We don't support the ciphersuite of the group we are trying to join.")]
UnsupportedCiphersuite,
#[error("Sender not found in tree.")]
UnknownSender,
#[error("The signature over the given group info is invalid.")]
InvalidGroupInfoSignature,
#[error("Error creating external commit.")]
CommitError,
#[error(transparent)]
PublicGroupError(#[from] CreationFromExternalError<StorageError>),
#[error("Credential is missing from external commit.")]
MissingCredential,
#[error("An error occurred when writing group to storage.")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum StageCommitError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The epoch of the group context and PublicMessage didn't match.")]
EpochMismatch,
#[error("The Commit was created by this client.")]
OwnCommit,
#[error("stage_commit was called with an PublicMessage that is not a Commit.")]
WrongPlaintextContentType,
#[error("Unable to verify the leaf node signature.")]
PathLeafNodeVerificationFailure,
#[error("Unable to determine commit path.")]
RequiredPathNotFound,
#[error("The confirmation Tag is missing.")]
ConfirmationTagMissing,
#[error("The confirmation tag is invalid.")]
ConfirmationTagMismatch,
#[error("The committer can't remove themselves.")]
AttemptedSelfRemoval,
#[error("The proposal queue is missing a proposal for the commit.")]
MissingProposal,
#[error("Missing own key to apply proposal.")]
OwnKeyNotFound,
#[error("External Committer used the wrong index.")]
InconsistentSenderIndex,
#[error("The sender is of type external, which is not valid.")]
SenderTypeExternal,
#[error("The sender is of type NewMemberProposal, which is not valid.")]
SenderTypeNewMemberProposal,
#[error("Too many new members: the tree is full.")]
TooManyNewMembers,
#[error(transparent)]
ProposalValidationError(#[from] ProposalValidationError),
#[error(transparent)]
PskError(#[from] PskError),
#[error(transparent)]
ExternalCommitValidation(#[from] ExternalCommitValidationError),
#[error(transparent)]
UpdatePathError(#[from] ApplyUpdatePathError),
#[error("Missing decryption key.")]
MissingDecryptionKey,
#[error(transparent)]
VerifiedUpdatePathError(#[from] UpdatePathError),
#[error(transparent)]
GroupContextExtensionsProposalValidationError(
#[from] GroupContextExtensionsProposalValidationError,
),
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateCommitError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Missing own key to apply proposal.")]
OwnKeyNotFound,
#[error("The Commit tried to remove self from the group. This is not possible.")]
CannotRemoveSelf,
#[error("The proposal queue is missing a proposal for the commit.")]
MissingProposal,
#[error("A proposal has the wrong sender type.")]
WrongProposalSenderType,
#[error(transparent)]
PskError(#[from] PskError),
#[error(transparent)]
ProposalValidationError(#[from] ProposalValidationError),
#[error(transparent)]
SignatureError(#[from] SignatureError),
#[error("Credential is missing from external commit.")]
MissingCredential,
#[error(transparent)]
PublicTreeError(#[from] PublicTreeError),
#[error(transparent)]
InvalidExtensionError(#[from] InvalidExtensionError),
#[error(transparent)]
GroupContextExtensionsProposalValidationError(
#[from] GroupContextExtensionsProposalValidationError,
),
#[error(transparent)]
TreeSyncAddLeaf(#[from] TreeSyncAddLeaf),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CommitBuilderStageError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Error interacting with storage.")]
KeyStoreError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ValidationError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Message group ID differs from the group's group ID.")]
WrongGroupId,
#[error("Message epoch differs from the group's epoch.")]
WrongEpoch,
#[error("The PublicMessage is not a Commit despite the sender begin of type NewMemberCommit.")]
NotACommit,
#[error("The PublicMessage is not an external Add proposal despite the sender begin of type NewMemberProposal.")]
NotAnExternalAddProposal,
#[error("The Commit doesn't have a path despite the sender being of type NewMemberCommit.")]
NoPath,
#[error("The PublicMessage contains an application message but was not encrypted.")]
UnencryptedApplicationMessage,
#[error("Sender is not part of the group.")]
UnknownMember,
#[error("Membership tag is missing.")]
MissingMembershipTag,
#[error("Membership tag is invalid.")]
InvalidMembershipTag,
#[error("The confirmation tag is missing.")]
MissingConfirmationTag,
#[error("Wrong wire format.")]
WrongWireFormat,
#[error("Verifying the signature failed.")]
InvalidSignature,
#[error("An application message was sent from an external sender.")]
NonMemberApplicationMessage,
#[error(transparent)]
UnableToDecrypt(#[from] MessageDecryptionError),
#[error("The message is from an epoch too far in the past.")]
NoPastEpochData,
#[error("The provided external sender is not authorized to send external proposals")]
UnauthorizedExternalSender,
#[error("The group doesn't contain external senders extension")]
NoExternalSendersExtension,
#[error(transparent)]
KeyPackageVerifyError(#[from] KeyPackageVerifyError),
#[error(transparent)]
UpdatePathError(#[from] UpdatePathError),
#[error("Invalid LeafNode signature.")]
InvalidLeafNodeSignature,
#[error("Invalid LeafNode source type")]
InvalidLeafNodeSourceType,
#[error("Invalid sender type")]
InvalidSenderType,
#[error("The Commit includes update proposals from the committer.")]
CommitterIncludedOwnUpdate,
#[error(
"The ciphersuite in the KeyPackage of the Add proposal does not match the group context."
)]
InvalidAddProposalCiphersuite,
#[error("Cannot decrypt own messages.")]
CannotDecryptOwnMessage,
#[error(transparent)]
ExternalCommitValidation(#[from] ExternalCommitValidationError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ProposalValidationError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The sender could not be matched to a member of the group.")]
UnknownMember,
#[error("Duplicate signature key in proposals and group.")]
DuplicateSignatureKey,
#[error("Duplicate encryption key in proposals and group.")]
DuplicateEncryptionKey,
#[error("Duplicate init key in proposals.")]
DuplicateInitKey,
#[error("The HPKE init and encryption keys are the same.")]
InitEncryptionKeyCollision,
#[error("Duplicate remove proposals for the same member.")]
DuplicateMemberRemoval,
#[error("The remove proposal referenced a non-existing member.")]
UnknownMemberRemoval,
#[error("Found an update from a non-member.")]
UpdateFromNonMember,
#[error("The Commit includes update proposals from the committer.")]
CommitterIncludedOwnUpdate,
#[error("The capabilities of the add proposal are insufficient for this group.")]
InsufficientCapabilities,
#[error(
"The add proposal's ciphersuite or protocol version do not match the ones in the group context."
)]
InvalidAddProposalCiphersuiteOrVersion,
#[error(transparent)]
Psk(#[from] PskError),
#[error("The proposal type is not supported by all group members.")]
UnsupportedProposalType,
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
#[error("Found ExternalInit proposal in regular commit")]
ExternalInitProposalInRegularCommit,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ExternalCommitValidationError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("No ExternalInit proposal found.")]
NoExternalInitProposals,
#[error("Multiple ExternalInit proposal found.")]
MultipleExternalInitProposals,
#[error("Found inline Add or Update proposals.")]
InvalidInlineProposals,
#[error("Found multiple inline Remove proposals.")]
MultipleRemoveProposals,
#[error("Remove proposal targets the wrong group member.")]
InvalidRemoveProposal,
#[error("External Commit has to contain a path.")]
NoPath,
#[error("Found a referenced proposal in an External Commit.")]
ReferencedProposal,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateAddProposalError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub(crate) enum ProposalQueueError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Not all proposals in the Commit were found locally.")]
ProposalNotFound,
#[error("Update proposal from external sender.")]
UpdateFromExternalSender,
#[error("SelfRemove proposal from a non-Member.")]
SelfRemoveFromNonMember,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub(crate) enum FromCommittedProposalsError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Not all proposals in the Commit were found locally.")]
ProposalNotFound,
#[error("The sender of a Commit tried to remove themselves.")]
SelfRemoval,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum CreateGroupContextExtProposalError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
KeyPackageExtensionSupport(#[from] KeyPackageExtensionSupportError),
#[error(transparent)]
Extension(#[from] ExtensionError),
#[error(transparent)]
LeafNodeValidation(#[from] LeafNodeValidationError),
#[error(transparent)]
MlsGroupStateError(#[from] MlsGroupStateError),
#[error(transparent)]
CreateCommitError(#[from] CreateCommitError),
#[error(transparent)]
CommitBuilderStageError(#[from] CommitBuilderStageError<StorageError>),
#[error("Error writing updated group data to storage.")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum MergeCommitError<StorageError> {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Error writing updated group data to storage.")]
StorageError(StorageError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum GroupContextExtensionsProposalValidationError {
#[error("Commit has more than one GroupContextExtensions proposal.")]
TooManyGCEProposals,
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(
"The new required capabilties contain extension types that are not supported by all group members."
)]
ExtensionNotSupportedByAllMembers,
#[error("Proposal changes the immutable metadata extension, which is not allowed.")]
ChangedImmutableMetadata,
#[error(
"The new required capabilties contain extension types that are not supported by all group members."
)]
RequiredExtensionNotSupportedByAllMembers,
#[error(
"An extension in the group context extensions is not listed in the required capabilties' extension types."
)]
ExtensionNotInRequiredCapabilities,
}