core_crypto/transaction_context/
error.rs1#![allow(missing_docs)]
3
4use super::e2e_identity;
5use crate::{ConversationId, mls::conversation::pending_conversation::PendingConversation};
6
7pub type Result<T, E = Error> = core::result::Result<T, E>;
9
10#[derive(Debug, thiserror::Error)]
12pub enum Error {
13 #[error("caller error: {0}")]
14 CallerError(&'static str),
15 #[error("This transaction context has already been finished and can no longer be used.")]
16 InvalidTransactionContext,
17 #[error("The conversation with the specified id is pending")]
18 PendingConversation(PendingConversation),
19 #[error("Couldn't find client")]
20 ClientNotFound(crate::ClientId),
21 #[error("Proteus client hasn't been initialized")]
22 ProteusNotInitialized,
23 #[error("Serializing {item} for TLS")]
24 TlsSerialize {
25 item: &'static str,
26 #[source]
27 source: tls_codec::Error,
28 },
29 #[error("Deserializing {item} for TLS")]
30 TlsDeserialize {
31 item: &'static str,
32 #[source]
33 source: tls_codec::Error,
34 },
35 #[error(transparent)]
36 E2EIdentity(#[from] e2e_identity::Error),
37 #[error(transparent)]
38 Keystore(#[from] crate::KeystoreError),
39 #[error(transparent)]
40 Mls(#[from] crate::MlsError),
41 #[error("Credentials of type {0} are unknown")]
42 UnknownCredential(u16),
43 #[error("this credential is still in use by the conversation with id \"{}\"", hex::encode(.0))]
44 CredentialStillInUse(ConversationId),
45 #[error("The supplied credential does not match the id this CC instance was initialized with")]
46 WrongCredential,
47 #[error("something went wrong when generating and storing a new keypackage: {0}")]
48 KeypackageNew(String),
49 #[error("{0}")]
50 Leaf(#[from] crate::LeafError),
51 #[error(transparent)]
52 Recursive(#[from] crate::RecursiveError),
53}
54
55impl Error {
56 pub fn tls_serialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
57 move |source| Self::TlsSerialize { item, source }
58 }
59
60 pub fn tls_deserialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
61 move |source| Self::TlsDeserialize { item, source }
62 }
63
64 pub fn keypackage_new<E: std::error::Error>() -> impl FnOnce(E) -> Self {
65 move |source| Self::KeypackageNew(source.to_string())
66 }
67}