Skip to main content

openmls/key_packages/
errors.rs

1//! # Key Package errors
2//!
3//! `KeyPackageError` are thrown on errors handling `KeyPackage`s.
4
5use openmls_traits::types::Ciphersuite;
6use thiserror::Error;
7
8use crate::{
9    ciphersuite::signable::SignatureError,
10    error::LibraryError,
11    prelude::ExtensionTypeNotValidInKeyPackageError,
12    treesync::{errors::LifetimeError, node::leaf_node::LeafNodeBuildError},
13};
14
15/// KeyPackage verify error
16#[derive(Error, Debug, PartialEq, Clone)]
17pub enum KeyPackageVerifyError {
18    /// See [`LibraryError`] for more details.
19    #[error(transparent)]
20    LibraryError(#[from] LibraryError),
21    /// See [`LifetimeError`] for more details.
22    #[error(transparent)]
23    LifetimeError(#[from] LifetimeError),
24    /// The lifetime of the leaf node is missing.
25    #[error("The lifetime of the leaf node is missing.")]
26    MissingLifetime,
27    /// A key package extension is not supported in the leaf's capabilities.
28    #[error("A key package extension is not supported in the leaf's capabilities.")]
29    UnsupportedExtension,
30    /// The key package signature is not valid.
31    #[error("The key package signature is not valid.")]
32    InvalidSignature,
33    /// The leaf node signature is not valid.
34    #[error("The leaf node signature is not valid.")]
35    InvalidLeafNodeSignature,
36    /// Invalid LeafNode source type
37    #[error("Invalid LeafNode source type")]
38    InvalidLeafNodeSourceType,
39    /// The init key and the encryption key are equal.
40    #[error("The init key and the encryption key are equal.")]
41    InitKeyEqualsEncryptionKey,
42    /// The protocol version is not valid.
43    #[error("The protocol version is not valid.")]
44    InvalidProtocolVersion,
45    /// The ciphersuite is not supported by the crypto provider.
46    #[error("Ciphersuite {0:?} is not supported by the crypto provider.")]
47    UnsupportedCiphersuite(Ciphersuite),
48    /// The provided extension is not allowed in key packages
49    #[error(transparent)]
50    ExtensionTypeNotValidInKeyPackage(#[from] ExtensionTypeNotValidInKeyPackageError),
51}
52
53/// KeyPackage extension support error
54#[derive(Error, Debug, PartialEq, Eq, Clone)]
55pub enum KeyPackageExtensionSupportError {
56    /// The key package does not support all required extensions.
57    #[error("The key package does not support all required extensions.")]
58    UnsupportedExtension,
59}
60
61/// KeyPackage new error
62#[derive(Error, Debug, PartialEq, Clone)]
63pub enum KeyPackageNewError {
64    /// See [`LibraryError`] for more details.
65    #[error(transparent)]
66    LibraryError(#[from] LibraryError),
67    /// The ciphersuite does not match the signature scheme.
68    #[error("The ciphersuite does not match the signature scheme.")]
69    CiphersuiteSignatureSchemeMismatch,
70    /// The ciphersuite is not supported by the crypto provider.
71    #[error("Ciphersuite {0:?} is not supported by the crypto provider.")]
72    UnsupportedCiphersuite(Ciphersuite),
73    /// Accessing storage failed.
74    #[error("Accessing storage failed.")]
75    StorageError,
76    /// See [`SignatureError`] for more details.
77    #[error(transparent)]
78    SignatureError(#[from] SignatureError),
79    /// The leaf node's capabilities don't cover what the leaf itself uses.
80    #[error(transparent)]
81    LeafNodeBuild(#[from] LeafNodeBuildError),
82    /// A virtual-clients operation failed while building the key package.
83    #[cfg(feature = "virtual-clients-draft")]
84    #[error(transparent)]
85    VirtualClientsError(#[from] crate::components::vc_derivation_info::VirtualClientsError),
86    /// A virtual-clients KeyPackage batch was requested with a count of 0.
87    #[cfg(feature = "virtual-clients-draft")]
88    #[error("A virtual-clients KeyPackage batch must request at least one KeyPackage.")]
89    EmptyBatch,
90}