1use thiserror::Error;
6
7use super::*;
8use crate::{
9 binary_tree::MlsBinaryTreeDiffError, ciphersuite::signable::SignatureError, error::LibraryError,
10};
11
12#[derive(Error, Debug, PartialEq, Eq, Clone)]
16pub enum PublicTreeError {
17 #[error(transparent)]
19 LibraryError(#[from] LibraryError),
20 #[error("The derived public key doesn't match the one in the tree.")]
22 PublicKeyMismatch,
23 #[error("Found two KeyPackages with the same public key.")]
25 DuplicateKeyPackage,
26 #[error("Couldn't find our own key package in this tree.")]
28 MissingKeyPackage,
29 #[error("The tree is malformed.")]
31 MalformedTree,
32 #[error("A parent hash was invalid.")]
34 InvalidParentHash,
35 #[error("An update failed because the provided credential has a different identity than the one in the leaf node.")]
37 IdentityMismatch,
38 #[error(transparent)]
40 SignatureError(#[from] SignatureError),
41}
42
43#[derive(Error, Debug, PartialEq, Clone)]
45pub enum ApplyUpdatePathError {
46 #[error(transparent)]
48 LibraryError(#[from] LibraryError),
49 #[error(
51 "The length of the received update path and that of the sender's direct path do not match."
52 )]
53 PathLengthMismatch,
54 #[error("The received update path and the derived nodes are not identical.")]
56 PathMismatch,
57 #[error("The parent hash of the ney key package is invalid.")]
59 ParentHashMismatch,
60 #[error("The parent hash of the ney key package is missing.")]
62 MissingParentHash,
63 #[error("Unable to decrypt the path node.")]
65 UnableToDecrypt,
66 #[error("Unable to find sender in tree.")]
68 MissingSender,
69 #[error("Tree is already at maximum size.")]
71 TreeFull,
72 #[error("External Committer used the wrong index.")]
74 InconsistentSenderIndex,
75}
76
77#[allow(dead_code)]
81#[derive(Error, Debug, PartialEq, Clone)]
83pub(crate) enum TreeSyncError {
84 #[error(transparent)]
86 LibraryError(#[from] LibraryError),
87 #[error("The leaf does not exist in the tree.")]
89 LeafNotInTree,
90 #[error(transparent)]
92 SetPathError(#[from] DerivePathError),
93 #[error(transparent)]
95 BinaryTreeError(#[from] MlsBinaryTreeError),
96 #[error(transparent)]
98 TreeSyncDiffError(#[from] TreeSyncDiffError),
99 #[error(transparent)]
101 DerivationError(#[from] PathSecretError),
102
103 #[error(transparent)]
105 CryptoError(#[from] CryptoError),
106 #[error("An extension type is not supported by a leaf in the tree.")]
108 UnsupportedExtension,
109 #[error("A capability is not supported by a leaf in the tree.")]
111 UnsupportedCapabilities,
112 #[error("A proposal is not supported by a leaf in the tree.")]
114 UnsupportedProposal,
115}
116
117#[derive(Error, Debug, PartialEq, Clone)]
119pub(crate) enum DerivePathError {
120 #[error(transparent)]
122 LibraryError(#[from] LibraryError),
123 #[error("The derived public key doesn't match the one in the tree.")]
125 PublicKeyMismatch,
126}
127
128#[derive(Error, Debug, PartialEq, Clone)]
130pub enum TreeSyncAddLeaf {
131 #[error(transparent)]
133 LibraryError(#[from] LibraryError),
134 #[error("The tree is full, we cannot add any more leaves.")]
136 TreeFull,
137}
138
139#[derive(Error, Debug, PartialEq, Clone)]
141pub enum TreeSyncFromNodesError {
142 #[error(transparent)]
144 LibraryError(#[from] LibraryError),
145 #[error(transparent)]
147 PublicTreeError(#[from] PublicTreeError),
148 #[error(transparent)]
150 RatchetTreeError(#[from] RatchetTreeError),
151}
152
153#[derive(Error, Debug, PartialEq, Clone)]
155pub(crate) enum TreeSyncParentHashError {
156 #[error(transparent)]
158 LibraryError(#[from] LibraryError),
159 #[error("Parent hash mismatch.")]
161 InvalidParentHash,
162}
163
164#[derive(Error, Debug, PartialEq, Clone)]
166pub(crate) enum TreeSyncDiffError {
167 #[error(transparent)]
169 LibraryError(#[from] LibraryError),
170 #[error(
171 "Couldn't find a fitting private key in the filtered resolution of the given leaf index."
172 )]
173 NoPrivateKeyFound,
174 #[error(transparent)]
176 TreeDiffError(#[from] MlsBinaryTreeDiffError),
177 #[error(transparent)]
179 DerivationError(#[from] PathSecretError),
180 #[error(transparent)]
182 CreationError(#[from] MlsBinaryTreeError),
183}
184
185#[derive(Error, Debug, PartialEq, Clone)]
187#[allow(clippy::enum_variant_names)]
188pub(crate) enum TreeKemError {
189 #[error(transparent)]
191 LibraryError(#[from] LibraryError),
192 #[error(transparent)]
194 TreeSyncError(#[from] TreeSyncError),
195 #[error(transparent)]
197 TreeSyncDiffError(#[from] TreeSyncDiffError),
198 #[error(transparent)]
200 PathSecretError(#[from] PathSecretError),
201}
202
203#[derive(Clone, Debug, Error, Eq, PartialEq)]
205pub enum LeafNodeValidationError {
206 #[error("Lifetime is not acceptable.")]
208 Lifetime(LifetimeError),
209 #[error("Extensions are not acceptable.")]
211 UnsupportedExtensions,
212 #[error("Proposals are not acceptable.")]
214 UnsupportedProposals,
215 #[error("Credentials are not acceptable.")]
217 UnsupportedCredentials,
218 #[error("The leaf node's credential type is not listed in the leaf node's capabilities.")]
220 CredentialNotInCapabilities,
221 #[error(
223 "The leaf node's extension types are not (all) listed in the leaf node's capabilities."
224 )]
225 ExtensionsNotInCapabilities,
226 #[error("The group's ciphersuite is not listed in the leaf node's capabilities.")]
228 CiphersuiteNotInCapabilities,
229 #[error("The leaf node's signature key is already used in the group.")]
231 SignatureKeyAlreadyInUse,
232 #[error("The leaf node's encryption key is already used in the group.")]
234 EncryptionKeyAlreadyInUse,
235 #[error("The leaf node source is invalid in the given context.")]
237 InvalidLeafNodeSource,
238 #[error("The leaf node credential is not supported by all members in the group.")]
240 LeafNodeCredentialNotSupportedByMember,
241 #[error("The credential used by a member is not supported by this leaf node.")]
243 MemberCredentialNotSupportedByLeafNode,
244}
245
246#[derive(Clone, Debug, Error, Eq, PartialEq)]
248pub enum LifetimeError {
249 #[error("Lifetime range is too wide.")]
251 RangeTooBig,
252 #[error("Lifetime doesn't cover current time.")]
254 NotCurrent,
255}
256
257#[derive(Debug, Clone, PartialEq, Eq, Error)]
259pub enum UpdatePathError {
260 #[error("The update path contains an invalid type of leaf node.")]
262 InvalidType,
263 #[error(transparent)]
265 SignatureError(#[from] SignatureError),
266}