1use thiserror::Error;
6
7use super::*;
8use crate::{
9 binary_tree::MlsBinaryTreeDiffError, ciphersuite::signable::SignatureError,
10 error::LibraryError, treesync::node::leaf_node::LeafNodeBuildError,
11};
12
13#[derive(Error, Debug, PartialEq, Eq, Clone)]
17pub enum PublicTreeError {
18 #[error(transparent)]
20 LibraryError(#[from] LibraryError),
21 #[error("The derived public key doesn't match the one in the tree.")]
23 PublicKeyMismatch,
24 #[error("Found two KeyPackages with the same public key.")]
26 DuplicateKeyPackage,
27 #[error("Couldn't find our own key package in this tree.")]
29 MissingKeyPackage,
30 #[error("The tree is malformed.")]
32 MalformedTree,
33 #[error("A parent hash was invalid.")]
35 InvalidParentHash,
36 #[error("An update failed because the provided credential has a different identity than the one in the leaf node.")]
38 IdentityMismatch,
39 #[error(transparent)]
41 SignatureError(#[from] SignatureError),
42}
43
44#[derive(Error, Debug, PartialEq, Clone)]
46pub enum ApplyUpdatePathError {
47 #[error(transparent)]
49 LibraryError(#[from] LibraryError),
50 #[error(
52 "The length of the received update path and that of the sender's direct path do not match."
53 )]
54 PathLengthMismatch,
55 #[error("The received update path and the derived nodes are not identical.")]
57 PathMismatch,
58 #[error("The parent hash of the ney key package is invalid.")]
60 ParentHashMismatch,
61 #[error("The parent hash of the ney key package is missing.")]
63 MissingParentHash,
64 #[error("Unable to decrypt the path node.")]
66 UnableToDecrypt,
67 #[error("Unable to find sender in tree.")]
69 MissingSender,
70 #[error("Tree is already at maximum size.")]
72 TreeFull,
73 #[error("External Committer used the wrong index.")]
75 InconsistentSenderIndex,
76 #[error("The own leaf is not in the tree.")]
78 MissingOwnLeaf,
79 #[error("The ciphertext is missing in the update path node.")]
81 MissingCiphertext,
82}
83
84#[allow(dead_code)]
88#[derive(Error, Debug, PartialEq, Clone)]
90pub(crate) enum TreeSyncError {
91 #[error(transparent)]
93 LibraryError(#[from] LibraryError),
94 #[error("The leaf does not exist in the tree.")]
96 LeafNotInTree,
97 #[error(transparent)]
99 SetPathError(#[from] DerivePathError),
100 #[error(transparent)]
102 BinaryTreeError(#[from] MlsBinaryTreeError),
103 #[error(transparent)]
105 TreeSyncDiffError(#[from] TreeSyncDiffError),
106 #[error(transparent)]
108 DerivationError(#[from] PathSecretError),
109
110 #[error(transparent)]
112 CryptoError(#[from] CryptoError),
113 #[error("An extension type is not supported by a leaf in the tree.")]
115 UnsupportedExtension,
116 #[error("A capability is not supported by a leaf in the tree.")]
118 UnsupportedCapabilities,
119 #[error("A proposal is not supported by a leaf in the tree.")]
121 UnsupportedProposal,
122}
123
124#[derive(Error, Debug, PartialEq, Clone)]
126pub(crate) enum DerivePathError {
127 #[error(transparent)]
129 LibraryError(#[from] LibraryError),
130 #[error("The derived public key doesn't match the one in the tree.")]
132 PublicKeyMismatch,
133}
134
135#[derive(Error, Debug, PartialEq, Clone)]
137pub enum TreeSyncAddLeaf {
138 #[error(transparent)]
140 LibraryError(#[from] LibraryError),
141 #[error("The tree is full, we cannot add any more leaves.")]
143 TreeFull,
144}
145
146#[derive(Error, Debug, PartialEq, Clone)]
151pub enum ApplyOwnUpdatePathError {
152 #[error(transparent)]
154 LibraryError(#[from] LibraryError),
155 #[error("The tree is full, we cannot add any more leaves.")]
157 TreeFull,
158 #[error(transparent)]
160 LeafNodeBuild(#[from] LeafNodeBuildError),
161}
162
163impl From<TreeSyncAddLeaf> for ApplyOwnUpdatePathError {
164 fn from(e: TreeSyncAddLeaf) -> Self {
165 match e {
166 TreeSyncAddLeaf::LibraryError(e) => Self::LibraryError(e),
167 TreeSyncAddLeaf::TreeFull => Self::TreeFull,
168 }
169 }
170}
171
172#[derive(Error, Debug, PartialEq, Clone)]
174pub enum TreeSyncFromNodesError {
175 #[error(transparent)]
177 LibraryError(#[from] LibraryError),
178 #[error(transparent)]
180 PublicTreeError(#[from] PublicTreeError),
181 #[error(transparent)]
183 RatchetTreeError(#[from] RatchetTreeError),
184}
185
186#[derive(Error, Debug, PartialEq, Clone)]
188pub(crate) enum TreeSyncParentHashError {
189 #[error(transparent)]
191 LibraryError(#[from] LibraryError),
192 #[error("Parent hash mismatch.")]
194 InvalidParentHash,
195}
196
197#[derive(Error, Debug, PartialEq, Clone)]
199pub(crate) enum TreeSyncDiffError {
200 #[error(transparent)]
202 LibraryError(#[from] LibraryError),
203 #[error(
204 "Couldn't find a fitting private key in the filtered resolution of the given leaf index."
205 )]
206 NoPrivateKeyFound,
207 #[error(transparent)]
209 TreeDiffError(#[from] MlsBinaryTreeDiffError),
210 #[error(transparent)]
212 DerivationError(#[from] PathSecretError),
213 #[error(transparent)]
215 CreationError(#[from] MlsBinaryTreeError),
216}
217
218#[derive(Clone, Debug, Error, Eq, PartialEq)]
220pub enum LeafNodeValidationError {
221 #[error(transparent)]
223 Lifetime(#[from] LifetimeError),
224 #[error("Extensions are not acceptable.")]
226 UnsupportedExtensions,
227 #[error("Proposals are not acceptable.")]
229 UnsupportedProposals,
230 #[error("Credentials are not acceptable.")]
232 UnsupportedCredentials,
233 #[error("The leaf node's credential type is not listed in the leaf node's capabilities.")]
235 CredentialNotInCapabilities,
236 #[error(
238 "The leaf node's extension types are not (all) listed in the leaf node's capabilities."
239 )]
240 ExtensionsNotInCapabilities,
241 #[error("The group's ciphersuite is not listed in the leaf node's capabilities.")]
243 CiphersuiteNotInCapabilities,
244 #[error("The leaf node's signature key is already used in the group.")]
246 SignatureKeyAlreadyInUse,
247 #[error("The leaf node's encryption key is already used in the group.")]
249 EncryptionKeyAlreadyInUse,
250 #[error("The leaf node source is invalid in the given context.")]
252 InvalidLeafNodeSource,
253 #[error("The leaf node credential is not supported by all members in the group.")]
255 LeafNodeCredentialNotSupportedByMember,
256 #[error("The credential used by a member is not supported by this leaf node.")]
258 MemberCredentialNotSupportedByLeafNode,
259}
260
261#[derive(Clone, Debug, Error, Eq, PartialEq)]
263pub enum LifetimeError {
264 #[error("Lifetime is in the past: not_after={not_after}, now={now}.")]
266 Expired {
267 not_after: u64,
269 now: u64,
271 },
272 #[error("Lifetime is in the future: not_before={not_before}, now={now}.")]
274 NotValidYet {
275 not_before: u64,
277 now: u64,
279 },
280 #[error("System time is before UNIX epoch.")]
282 SystemTimeBeforeUnixEpoch,
283}
284
285#[derive(Debug, Clone, PartialEq, Eq, Error)]
287pub enum UpdatePathError {
288 #[error("The update path contains an invalid type of leaf node.")]
290 InvalidType,
291 #[error(transparent)]
293 SignatureError(#[from] SignatureError),
294}