Skip to main content

openmls/treesync/
errors.rs

1//! TreeSync errors
2//!
3//! This module exposes [`ApplyUpdatePathError`] and [`PublicTreeError`].
4
5use thiserror::Error;
6
7use super::*;
8use crate::{
9    binary_tree::MlsBinaryTreeDiffError, ciphersuite::signable::SignatureError, error::LibraryError,
10};
11
12// === Public errors ===
13
14/// Public tree error
15#[derive(Error, Debug, PartialEq, Eq, Clone)]
16pub enum PublicTreeError {
17    /// See [`LibraryError`] for more details.
18    #[error(transparent)]
19    LibraryError(#[from] LibraryError),
20    /// The derived public key doesn't match the one in the tree.
21    #[error("The derived public key doesn't match the one in the tree.")]
22    PublicKeyMismatch,
23    /// Found two KeyPackages with the same public key.
24    #[error("Found two KeyPackages with the same public key.")]
25    DuplicateKeyPackage,
26    /// Couldn't find our own key package in this tree.
27    #[error("Couldn't find our own key package in this tree.")]
28    MissingKeyPackage,
29    /// The tree is malformed.
30    #[error("The tree is malformed.")]
31    MalformedTree,
32    /// A parent hash was invalid.
33    #[error("A parent hash was invalid.")]
34    InvalidParentHash,
35    /// An update failed because the provided credential has a different identity than the one in the leaf node.
36    #[error("An update failed because the provided credential has a different identity than the one in the leaf node.")]
37    IdentityMismatch,
38    /// See [`SignatureError`] for more details.
39    #[error(transparent)]
40    SignatureError(#[from] SignatureError),
41}
42
43/// Apply update path error
44#[derive(Error, Debug, PartialEq, Clone)]
45pub enum ApplyUpdatePathError {
46    /// See [`LibraryError`] for more details.
47    #[error(transparent)]
48    LibraryError(#[from] LibraryError),
49    /// The length of the received update path and that of the sender's direct path do not match.
50    #[error(
51        "The length of the received update path and that of the sender's direct path do not match."
52    )]
53    PathLengthMismatch,
54    /// The received update path and the derived nodes are not identical.
55    #[error("The received update path and the derived nodes are not identical.")]
56    PathMismatch,
57    /// The parent hash of the ney key package is invalid.
58    #[error("The parent hash of the ney key package is invalid.")]
59    ParentHashMismatch,
60    /// The parent hash of the ney key package is missing.
61    #[error("The parent hash of the ney key package is missing.")]
62    MissingParentHash,
63    /// Unable to decrypt the path node.
64    #[error("Unable to decrypt the path node.")]
65    UnableToDecrypt,
66    /// Unable to find sender in tree.
67    #[error("Unable to find sender in tree.")]
68    MissingSender,
69    /// Tree is already at maximum size.
70    #[error("Tree is already at maximum size.")]
71    TreeFull,
72    /// External Committer used the wrong index.
73    #[error("External Committer used the wrong index.")]
74    InconsistentSenderIndex,
75    /// The own leaf is not in the tree.
76    #[error("The own leaf is not in the tree.")]
77    MissingOwnLeaf,
78    /// The ciphertext is missing in the update path node.
79    #[error("The ciphertext is missing in the update path node.")]
80    MissingCiphertext,
81}
82
83// === Crate errors ===
84
85// `UnsupportedExtension` is only used in tests for now
86#[allow(dead_code)]
87/// TreeSync error
88#[derive(Error, Debug, PartialEq, Clone)]
89pub(crate) enum TreeSyncError {
90    /// See [`LibraryError`] for more details.
91    #[error(transparent)]
92    LibraryError(#[from] LibraryError),
93    /// A requested leaf is not in the tree.
94    #[error("The leaf does not exist in the tree.")]
95    LeafNotInTree,
96    /// See [`TreeSyncSetPathError`] for more details.
97    #[error(transparent)]
98    SetPathError(#[from] DerivePathError),
99    /// See [`MlsBinaryTreeError`] for more details.
100    #[error(transparent)]
101    BinaryTreeError(#[from] MlsBinaryTreeError),
102    /// See [`TreeSyncDiffError`] for more details.
103    #[error(transparent)]
104    TreeSyncDiffError(#[from] TreeSyncDiffError),
105    /// See [`PathSecretError`] for more details.
106    #[error(transparent)]
107    DerivationError(#[from] PathSecretError),
108
109    /// See [`CryptoError`] for more details.
110    #[error(transparent)]
111    CryptoError(#[from] CryptoError),
112    /// An extension type is not supported by a leaf in the tree.
113    #[error("An extension type is not supported by a leaf in the tree.")]
114    UnsupportedExtension,
115    /// A capability is not supported by a leaf in the tree.
116    #[error("A capability is not supported by a leaf in the tree.")]
117    UnsupportedCapabilities,
118    /// A proposal is not supported by a leaf in the tree.
119    #[error("A proposal is not supported by a leaf in the tree.")]
120    UnsupportedProposal,
121}
122
123/// Derive path error
124#[derive(Error, Debug, PartialEq, Clone)]
125pub(crate) enum DerivePathError {
126    /// See [`LibraryError`] for more details.
127    #[error(transparent)]
128    LibraryError(#[from] LibraryError),
129    /// The derived public key doesn't match the one in the tree.
130    #[error("The derived public key doesn't match the one in the tree.")]
131    PublicKeyMismatch,
132}
133
134/// TreeSync set path error
135#[derive(Error, Debug, PartialEq, Clone)]
136pub enum TreeSyncAddLeaf {
137    /// See [`LibraryError`] for more details.
138    #[error(transparent)]
139    LibraryError(#[from] LibraryError),
140    /// The tree is full, we cannot add any more leaves.
141    #[error("The tree is full, we cannot add any more leaves.")]
142    TreeFull,
143}
144
145/// TreeSync from nodes error
146#[derive(Error, Debug, PartialEq, Clone)]
147pub enum TreeSyncFromNodesError {
148    /// See [`LibraryError`] for more details.
149    #[error(transparent)]
150    LibraryError(#[from] LibraryError),
151    /// See [`PublicTreeError`] for more details.
152    #[error(transparent)]
153    PublicTreeError(#[from] PublicTreeError),
154    /// See [`RatchetTreeError`] for more details.
155    #[error(transparent)]
156    RatchetTreeError(#[from] RatchetTreeError),
157}
158
159/// TreeSync parent hash error
160#[derive(Error, Debug, PartialEq, Clone)]
161pub(crate) enum TreeSyncParentHashError {
162    /// See [`LibraryError`] for more details.
163    #[error(transparent)]
164    LibraryError(#[from] LibraryError),
165    /// Parent hash mismatch.
166    #[error("Parent hash mismatch.")]
167    InvalidParentHash,
168}
169
170/// TreeSync parent hash error
171#[derive(Error, Debug, PartialEq, Clone)]
172pub(crate) enum TreeSyncDiffError {
173    /// See [`LibraryError`] for more details.
174    #[error(transparent)]
175    LibraryError(#[from] LibraryError),
176    #[error(
177        "Couldn't find a fitting private key in the filtered resolution of the given leaf index."
178    )]
179    NoPrivateKeyFound,
180    /// See [`MlsBinaryTreeDiffError`] for more details.
181    #[error(transparent)]
182    TreeDiffError(#[from] MlsBinaryTreeDiffError),
183    /// See [`PathSecretError`] for more details.
184    #[error(transparent)]
185    DerivationError(#[from] PathSecretError),
186    /// See [`MlsBinaryTreeError`] for more details.
187    #[error(transparent)]
188    CreationError(#[from] MlsBinaryTreeError),
189}
190
191/// Errors that can happen during leaf node validation.
192#[derive(Clone, Debug, Error, Eq, PartialEq)]
193pub enum LeafNodeValidationError {
194    /// Lifetime is not acceptable.
195    #[error("Lifetime is not acceptable.")]
196    Lifetime(LifetimeError),
197    /// Extensions are not acceptable.
198    #[error("Extensions are not acceptable.")]
199    UnsupportedExtensions,
200    /// Proposals are not acceptable.
201    #[error("Proposals are not acceptable.")]
202    UnsupportedProposals,
203    /// Credentials are not acceptable.
204    #[error("Credentials are not acceptable.")]
205    UnsupportedCredentials,
206    /// The leaf node's credential type is not listed in the leaf node's capabilities."
207    #[error("The leaf node's credential type is not listed in the leaf node's capabilities.")]
208    CredentialNotInCapabilities,
209    /// The leaf node's extension types are not (all) listed in the leaf node's capabilities.
210    #[error(
211        "The leaf node's extension types are not (all) listed in the leaf node's capabilities."
212    )]
213    ExtensionsNotInCapabilities,
214    /// The group's ciphersuite is not listed in the leaf node's capabilities.
215    #[error("The group's ciphersuite is not listed in the leaf node's capabilities.")]
216    CiphersuiteNotInCapabilities,
217    /// The leaf node's signature key is already used in the group.
218    #[error("The leaf node's signature key is already used in the group.")]
219    SignatureKeyAlreadyInUse,
220    /// The leaf node's encryption key is already used in the group.
221    #[error("The leaf node's encryption key is already used in the group.")]
222    EncryptionKeyAlreadyInUse,
223    /// The leaf node source is invalid in the given context.
224    #[error("The leaf node source is invalid in the given context.")]
225    InvalidLeafNodeSource,
226    /// The leaf node credential is not supported by all members in the group.
227    #[error("The leaf node credential is not supported by all members in the group.")]
228    LeafNodeCredentialNotSupportedByMember,
229    /// The credential used by a member is not supported by this leaf node.
230    #[error("The credential used by a member is not supported by this leaf node.")]
231    MemberCredentialNotSupportedByLeafNode,
232}
233
234/// Errors that can happen during lifetime validation.
235#[derive(Clone, Debug, Error, Eq, PartialEq)]
236pub enum LifetimeError {
237    /// Lifetime range is too wide.
238    #[error("Lifetime range is too wide.")]
239    RangeTooBig,
240    /// Lifetime doesn't cover current time.
241    #[error("Lifetime doesn't cover current time.")]
242    NotCurrent,
243}
244
245/// Errors that can happen during path validation.
246#[derive(Debug, Clone, PartialEq, Eq, Error)]
247pub enum UpdatePathError {
248    /// The update path contains an invalid type of leaf node.
249    #[error("The update path contains an invalid type of leaf node.")]
250    InvalidType,
251    /// See [`SignatureError`] for more details.
252    #[error(transparent)]
253    SignatureError(#[from] SignatureError),
254}