openmls/extensions/
errors.rs

1//! # Extension errors.
2//!
3//! An `ExtensionError` is thrown when an extension is invalid (for example when
4//! decoding from raw bytes) or when a check on an extension fails.
5//!
6//! `ExtensionError` holds individual errors for each extension.
7//! * `CapabilitiesExtensionError`
8//! * `KeyPackageIdError`
9//! * `ParentHashError`
10//! * `RatchetTreeError`
11
12use crate::error::{ErrorString, LibraryError};
13
14use thiserror::Error;
15
16/// Extension error
17#[derive(Error, Debug, PartialEq, Clone)]
18pub enum ExtensionError {
19    /// Unsupported proposal type in required capabilities.
20    #[error("Unsupported proposal type in required capabilities.")]
21    UnsupportedProposalType,
22    /// Unsupported extension type in required capabilities.
23    #[error("Unsupported extension type in required capabilities.")]
24    UnsupportedExtensionType,
25    /// See [`LibraryError`] for more details.
26    #[error(transparent)]
27    LibraryError(#[from] LibraryError),
28    /// See [`ErrorString`] for more details.
29    #[error(transparent)]
30    InvalidExtensionType(#[from] ErrorString),
31    /// See [`CapabilitiesExtensionError`] for more details.
32    #[error(transparent)]
33    Capabilities(#[from] CapabilitiesExtensionError),
34    /// See [`KeyPackageIdError`] for more details.
35    #[error(transparent)]
36    KeyPackageId(#[from] KeyPackageIdError),
37    /// See [`ParentHashError`] for more details.
38    #[error(transparent)]
39    ParentHash(#[from] ParentHashError),
40    /// See [`RatchetTreeError`] for more details.
41    #[error(transparent)]
42    RatchetTree(#[from] RatchetTreeError),
43    /// See [`InvalidExtensionError`] for more details.
44    #[error(transparent)]
45    InvalidExtension(#[from] InvalidExtensionError),
46}
47
48/// Capabilities extension error
49#[derive(Error, Debug, PartialEq, Eq, Clone)]
50pub enum CapabilitiesExtensionError {
51    /// Invalid capabilities extensions.
52    #[error("Invalid capabilities extensions.")]
53    Invalid,
54    /// Capabilities extension is missing a version field.
55    #[error("Capabilities extension is missing a version field.")]
56    EmptyVersionsField,
57    /// Capabilities contains only unsupported ciphersuites.
58    #[error("Capabilities contains only unsupported ciphersuites.")]
59    UnsupportedCiphersuite,
60}
61
62/// KeyPackage Id error
63#[derive(Error, Debug, PartialEq, Eq, Clone)]
64pub enum KeyPackageIdError {
65    /// Invalid key package ID extensions.
66    #[error("Invalid key package ID extensions.")]
67    Invalid,
68}
69
70/// Parent hash error
71#[derive(Error, Debug, PartialEq, Eq, Clone)]
72pub enum ParentHashError {
73    /// Invalid parent hash extensions.
74    #[error("Invalid parent hash extensions.")]
75    Invalid,
76}
77
78/// Ratchet tree error
79#[derive(Error, Debug, PartialEq, Eq, Clone)]
80pub enum RatchetTreeError {
81    /// Invalid ratchet tree extensions.
82    #[error("Invalid ratchet tree extensions.")]
83    Invalid,
84}
85
86/// Invalid extension error
87#[derive(Error, Debug, PartialEq, Eq, Clone)]
88pub enum InvalidExtensionError {
89    /// The provided extension list contains duplicate extensions.
90    #[error("The provided extension list contains duplicate extensions.")]
91    Duplicate,
92    /// The specified extension could not be found.
93    #[error("The specified extension could not be found.")]
94    NotFound,
95    /// The provided extension list contains an extension that is not allowed in group contexts
96    #[error(
97        "The provided extension list contains an extension that is not allowed in group contexts."
98    )]
99    IllegalInGroupContext,
100    /// The provided extension list contains an extension that is not allowed in leaf nodes
101    #[error(
102        "The provided extension list contains an extension that is not allowed in leaf nodes."
103    )]
104    IllegalInLeafNodes,
105}