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