use thiserror::Error;
use super::*;
use crate::{
binary_tree::MlsBinaryTreeDiffError, ciphersuite::signable::SignatureError, error::LibraryError,
};
#[derive(Error, Debug, PartialEq, Eq, Clone)]
pub enum PublicTreeError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The derived public key doesn't match the one in the tree.")]
PublicKeyMismatch,
#[error("Found two KeyPackages with the same public key.")]
DuplicateKeyPackage,
#[error("Couldn't find our own key package in this tree.")]
MissingKeyPackage,
#[error("The tree is malformed.")]
MalformedTree,
#[error("A parent hash was invalid.")]
InvalidParentHash,
#[error("An update failed because the provided credential has a different identity than the one in the leaf node.")]
IdentityMismatch,
#[error(transparent)]
SignatureError(#[from] SignatureError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum ApplyUpdatePathError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(
"The length of the received update path and that of the sender's direct path do not match."
)]
PathLengthMismatch,
#[error("The received update path and the derived nodes are not identical.")]
PathMismatch,
#[error("The parent hash of the ney key package is invalid.")]
ParentHashMismatch,
#[error("The parent hash of the ney key package is missing.")]
MissingParentHash,
#[error("Unable to decrypt the path node.")]
UnableToDecrypt,
#[error("Unable to find sender in tree.")]
MissingSender,
#[error("Tree is already at maximum size.")]
TreeFull,
#[error("External Committer used the wrong index.")]
InconsistentSenderIndex,
}
#[allow(dead_code)]
#[derive(Error, Debug, PartialEq, Clone)]
pub(crate) enum TreeSyncError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The leaf does not exist in the tree.")]
LeafNotInTree,
#[error(transparent)]
SetPathError(#[from] DerivePathError),
#[error(transparent)]
BinaryTreeError(#[from] MlsBinaryTreeError),
#[error(transparent)]
TreeSyncDiffError(#[from] TreeSyncDiffError),
#[error(transparent)]
DerivationError(#[from] PathSecretError),
#[error(transparent)]
CryptoError(#[from] CryptoError),
#[error("An extension type is not supported by a leaf in the tree.")]
UnsupportedExtension,
#[error("A capability is not supported by a leaf in the tree.")]
UnsupportedCapabilities,
#[error("A proposal is not supported by a leaf in the tree.")]
UnsupportedProposal,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub(crate) enum DerivePathError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The derived public key doesn't match the one in the tree.")]
PublicKeyMismatch,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum TreeSyncAddLeaf {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("The tree is full, we cannot add any more leaves.")]
TreeFull,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub enum TreeSyncFromNodesError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
PublicTreeError(#[from] PublicTreeError),
#[error(transparent)]
RatchetTreeError(#[from] RatchetTreeError),
}
#[derive(Error, Debug, PartialEq, Clone)]
pub(crate) enum TreeSyncParentHashError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error("Parent hash mismatch.")]
InvalidParentHash,
}
#[derive(Error, Debug, PartialEq, Clone)]
pub(crate) enum TreeSyncDiffError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(
"Couldn't find a fitting private key in the filtered resolution of the given leaf index."
)]
NoPrivateKeyFound,
#[error(transparent)]
TreeDiffError(#[from] MlsBinaryTreeDiffError),
#[error(transparent)]
DerivationError(#[from] PathSecretError),
#[error(transparent)]
CreationError(#[from] MlsBinaryTreeError),
}
#[derive(Error, Debug, PartialEq, Clone)]
#[allow(clippy::enum_variant_names)]
pub(crate) enum TreeKemError {
#[error(transparent)]
LibraryError(#[from] LibraryError),
#[error(transparent)]
TreeSyncError(#[from] TreeSyncError),
#[error(transparent)]
TreeSyncDiffError(#[from] TreeSyncDiffError),
#[error(transparent)]
PathSecretError(#[from] PathSecretError),
}
#[derive(Clone, Debug, Error, Eq, PartialEq)]
pub enum LeafNodeValidationError {
#[error("Lifetime is not acceptable.")]
Lifetime(LifetimeError),
#[error("Extensions are not acceptable.")]
UnsupportedExtensions,
#[error("Proposals are not acceptable.")]
UnsupportedProposals,
#[error("Credentials are not acceptable.")]
UnsupportedCredentials,
#[error("The leaf node's credential type is not listed in the leaf node's capabilities.")]
CredentialNotInCapabilities,
#[error(
"The leaf node's extension types are not (all) listed in the leaf node's capabilities."
)]
ExtensionsNotInCapabilities,
#[error("The group's ciphersuite is not listed in the leaf node's capabilities.")]
CiphersuiteNotInCapabilities,
#[error("The leaf node's signature key is already used in the group.")]
SignatureKeyAlreadyInUse,
#[error("The leaf node's encryption key is already used in the group.")]
EncryptionKeyAlreadyInUse,
#[error("The leaf node source is invalid in the given context.")]
InvalidLeafNodeSource,
#[error("The leaf node credential is not supported by all members in the group.")]
LeafNodeCredentialNotSupportedByMember,
#[error("The credential used by a member is not supported by this leaf node.")]
MemberCredentialNotSupportedByLeafNode,
}
#[derive(Clone, Debug, Error, Eq, PartialEq)]
pub enum LifetimeError {
#[error("Lifetime range is too wide.")]
RangeTooBig,
#[error("Lifetime doesn't cover current time.")]
NotCurrent,
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum UpdatePathError {
#[error("The update path contains an invalid type of leaf node.")]
InvalidType,
#[error(transparent)]
SignatureError(#[from] SignatureError),
}