core_crypto/transaction_context/
error.rs1#![allow(missing_docs)]
3
4use super::e2e_identity;
5use crate::{ConversationId, CredentialRef, 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("The supplied credential is invalid")]
48 InvalidCredential,
49 #[error(
50 "There are invalid CredentialRefs that should be removed. Hex encoded sha256 hashes: {}",
51 format_invalid_credential_refs(.0)
52 )]
53 InvalidCredentials(Vec<CredentialRef>),
54 #[error("something went wrong when generating and storing a new keypackage: {0}")]
55 KeypackageNew(String),
56 #[error("{0}")]
57 Leaf(#[from] crate::LeafError),
58 #[error(transparent)]
59 Recursive(#[from] crate::RecursiveError),
60}
61
62fn format_invalid_credential_refs(credential_refs: &[CredentialRef]) -> String {
63 credential_refs
64 .iter()
65 .map(|credential_ref| credential_ref.public_key_hash().to_string())
66 .collect::<Vec<_>>()
67 .join(", ")
68}
69
70impl Error {
71 pub fn tls_serialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
72 move |source| Self::TlsSerialize { item, source }
73 }
74
75 pub fn tls_deserialize(item: &'static str) -> impl FnOnce(tls_codec::Error) -> Self {
76 move |source| Self::TlsDeserialize { item, source }
77 }
78
79 pub fn keypackage_new<E: std::error::Error>() -> impl FnOnce(E) -> Self {
80 move |source| Self::KeypackageNew(source.to_string())
81 }
82}