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