Skip to main content

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 std::convert::Infallible;
13
14use crate::{
15    error::{ErrorString, LibraryError},
16    extensions::ExtensionType,
17};
18
19use thiserror::Error;
20
21/// Extension error
22#[derive(Error, Debug, PartialEq, Clone)]
23pub enum ExtensionError {
24    /// Unsupported proposal type in required capabilities.
25    #[error("Unsupported proposal type in required capabilities.")]
26    UnsupportedProposalType,
27    /// Unsupported extension type in required capabilities.
28    #[error("Unsupported extension type in required capabilities.")]
29    UnsupportedExtensionType,
30    /// See [`LibraryError`] for more details.
31    #[error(transparent)]
32    LibraryError(#[from] LibraryError),
33    /// See [`ErrorString`] for more details.
34    #[error(transparent)]
35    InvalidExtensionType(#[from] ErrorString),
36    /// See [`CapabilitiesExtensionError`] for more details.
37    #[error(transparent)]
38    Capabilities(#[from] CapabilitiesExtensionError),
39    /// See [`KeyPackageIdError`] for more details.
40    #[error(transparent)]
41    KeyPackageId(#[from] KeyPackageIdError),
42    /// See [`ParentHashError`] for more details.
43    #[error(transparent)]
44    ParentHash(#[from] ParentHashError),
45    /// See [`RatchetTreeError`] for more details.
46    #[error(transparent)]
47    RatchetTree(#[from] RatchetTreeError),
48    /// See [`InvalidExtensionError`] for more details.
49    #[error(transparent)]
50    InvalidExtension(#[from] InvalidExtensionError),
51}
52
53/// Capabilities extension error
54#[derive(Error, Debug, PartialEq, Eq, Clone)]
55pub enum CapabilitiesExtensionError {
56    /// Invalid capabilities extensions.
57    #[error("Invalid capabilities extensions.")]
58    Invalid,
59    /// Capabilities extension is missing a version field.
60    #[error("Capabilities extension is missing a version field.")]
61    EmptyVersionsField,
62    /// Capabilities contains only unsupported ciphersuites.
63    #[error("Capabilities contains only unsupported ciphersuites.")]
64    UnsupportedCiphersuite,
65}
66
67/// KeyPackage Id error
68#[derive(Error, Debug, PartialEq, Eq, Clone)]
69pub enum KeyPackageIdError {
70    /// Invalid key package ID extensions.
71    #[error("Invalid key package ID extensions.")]
72    Invalid,
73}
74
75/// Parent hash error
76#[derive(Error, Debug, PartialEq, Eq, Clone)]
77pub enum ParentHashError {
78    /// Invalid parent hash extensions.
79    #[error("Invalid parent hash extensions.")]
80    Invalid,
81}
82
83/// Ratchet tree error
84#[derive(Error, Debug, PartialEq, Eq, Clone)]
85pub enum RatchetTreeError {
86    /// Invalid ratchet tree extensions.
87    #[error("Invalid ratchet tree extensions.")]
88    Invalid,
89}
90
91/// Invalid extension error
92#[derive(Error, Debug, PartialEq, Eq, Clone)]
93pub enum InvalidExtensionError {
94    /// The provided extension list contains duplicate extensions.
95    #[error("The provided extension list contains duplicate extensions.")]
96    Duplicate,
97    /// The specified extension could not be found.
98    #[error("The specified extension could not be found.")]
99    NotFound,
100    /// The provided extension list contains an extension type that is not allowed in leaf nodes
101    #[error(transparent)]
102    ExtensionTypeNotValidInLeafNode(#[from] ExtensionTypeNotValidInLeafNodeError),
103    /// The provided extension list contains an extension type that is not allowed in the group
104    /// context
105    #[error(transparent)]
106    ExtensionTypeNotValidInGroupContext(#[from] ExtensionTypeNotValidInGroupContextError),
107    /// The provided extension list contains an extension type that is not allowed in key packages
108    #[error(transparent)]
109    ExtensionTypeNotValidInKeyPackage(#[from] ExtensionTypeNotValidInKeyPackageError),
110    /// The provided extension list contains an extension type that is not allowed in the group
111    /// info
112    #[error(transparent)]
113    ExtensionTypeNotValidInGroupInfo(#[from] ExtensionTypeNotValidInGroupInfoError),
114    /// The provided extension cannot be added directly to the GroupInfo
115    #[error("The provided extension cannot be added directly to the GroupInfo.")]
116    CannotAddDirectlyToGroupInfo,
117}
118
119/// The provided extension list contains an extension type that is not allowed in the group info
120#[derive(Error, Debug, PartialEq, Eq, Clone)]
121#[error(
122        "The provided extension list contains an extension of type {0:?} that is not allowed in the group info."
123    )]
124pub struct ExtensionTypeNotValidInGroupInfoError(pub ExtensionType);
125
126/// The provided extension list contains an extension type that is not allowed in the group context
127#[derive(Error, Debug, PartialEq, Eq, Clone)]
128#[error(
129        "The provided extension list contains an extension of type {0:?} that is not allowed in the group context."
130    )]
131pub struct ExtensionTypeNotValidInGroupContextError(pub ExtensionType);
132
133/// The provided extension list contains an extension type that is not allowed in leaf nodes
134#[derive(Error, Debug, PartialEq, Eq, Clone)]
135#[error(
136        "The provided extension list contains an extension of type {0:?} that is not allowed in leaf nodes."
137    )]
138pub struct ExtensionTypeNotValidInLeafNodeError(pub ExtensionType);
139
140/// The provided extension list contains an extension type that is not allowed in key packages
141#[derive(Error, Debug, PartialEq, Eq, Clone)]
142#[error(
143        "The provided extension list contains an extension of type {0:?} that is not allowed in key packages."
144    )]
145pub struct ExtensionTypeNotValidInKeyPackageError(pub ExtensionType);
146
147impl From<Infallible> for InvalidExtensionError {
148    fn from(value: Infallible) -> Self {
149        match value {}
150    }
151}