core_crypto/mls/client/
error.rs

1//! MLS errors
2
3// We allow missing documentation in the error module because the types are generally self-descriptive.
4#![allow(missing_docs)]
5
6pub(crate) type Result<T, E = Error> = core::result::Result<T, E>;
7
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    #[error("Supplied user id was not valid")]
11    InvalidUserId,
12    #[error("X509 certificate bundle set was empty")]
13    NoX509CertificateBundle,
14    #[error("Tried to insert an already existing CredentialBundle")]
15    CredentialBundleConflict,
16    #[error("A MLS operation was requested but MLS hasn't been initialized on this instance")]
17    MlsNotInitialized,
18    #[error("A Credential of type {0:?} was not found locally which is very likely an implementation error")]
19    CredentialNotFound(crate::prelude::MlsCredentialType),
20    #[error("supplied signature scheme was not valid")]
21    InvalidSignatureScheme,
22    #[error("Keypackage list was empty")]
23    EmptyKeypackageList,
24    /// The keystore has no knowledge of such client; this shouldn't happen as Client::init is failsafe (find-else-create)
25    #[error("The provided client signature has not been found in the keystore")]
26    ClientSignatureNotFound,
27    /// Client was unexpectedly ready.
28    ///
29    /// This indicates an invalid calling pattern.
30    #[error("Client was unexpectedly ready")]
31    UnexpectedlyReady,
32    #[error("The keystore already contains a stored identity. Cannot create a new one!")]
33    IdentityAlreadyPresent,
34    #[error(
35        r#"The externally-generated client ID initialization cannot continue - there's no provisional keypair in-store!
36
37        Have you called `CoreCrypto::generate_raw_keypair` ?"#
38    )]
39    NoProvisionalIdentityFound,
40    /// This error occurs when during the MLS external client generation, we end up with more than one client identity in store.
41    ///
42    /// This is usually not possible, unless there's some kind of concurrency issue
43    /// on the consumer (creating an ext-gen client AND a normal one at the same time for instance)
44    #[error(
45        "Somehow CoreCrypto holds more than one MLS identity. Something might've gone very wrong with this client!"
46    )]
47    TooManyIdentitiesPresent,
48    #[error("The supplied credential does not match the id or signature schemes provided")]
49    WrongCredential,
50    #[error("An EpochObserver has already been registered; reregistration is not possible")]
51    EpochObserverAlreadyExists,
52    #[error("Serializing {item} for TLS")]
53    TlsSerialize {
54        item: &'static str,
55        #[source]
56        source: tls_codec::Error,
57    },
58    #[error("Deserializing {item} for TLS")]
59    TlsDeserialize {
60        item: &'static str,
61        #[source]
62        source: tls_codec::Error,
63    },
64    #[error(transparent)]
65    Mls(#[from] crate::MlsError),
66    #[error(transparent)]
67    Keystore(#[from] crate::KeystoreError),
68    #[error("{0}")]
69    Leaf(#[from] crate::LeafError),
70    #[error(transparent)]
71    Recursive(#[from] crate::RecursiveError),
72}
73
74impl Error {
75    pub fn tls_serialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
76        move |source| Self::TlsSerialize { item, source }
77    }
78
79    pub fn tls_deserialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
80        move |source| Self::TlsDeserialize { item, source }
81    }
82}