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