core_crypto/transaction_context/
error.rs1#![allow(missing_docs)]
3
4use crate::{ConversationId, CredentialRef, mls::conversation::PendingConversation};
5
6pub type Result<T, E = Error> = core::result::Result<T, E>;
8
9#[derive(Debug, thiserror::Error)]
11pub enum Error {
12 #[error("caller error: {0}")]
13 CallerError(&'static str),
14 #[error("This transaction context has already been finished and can no longer be used.")]
15 InvalidTransactionContext,
16 #[error("Conversation already exists")]
18 ConversationAlreadyExists(ConversationId),
19 #[error("Couldn't find conversation")]
21 ConversationNotFound(ConversationId),
22 #[error("The conversation with the specified id is pending")]
23 PendingConversation(PendingConversation),
24 #[error("Proteus client hasn't been initialized")]
25 ProteusNotInitialized,
26 #[error("PKI Environment must be set before calling this function")]
27 PkiEnvironmentUnset,
28 #[error(transparent)]
29 Keystore(#[from] crate::KeystoreError),
30 #[error(transparent)]
31 OpenMls(#[from] crate::OpenMlsError),
32 #[error("this credential is still in use by the conversation with id \"{}\"", hex::encode(.0))]
33 CredentialStillInUse(ConversationId),
34 #[error("The supplied credential does not match the id this CC instance was initialized with")]
35 WrongCredential,
36 #[error(
37 "There are invalid CredentialRefs that should be removed. Hex encoded sha256 hashes: {}",
38 format_invalid_credential_refs(.0)
39 )]
40 InvalidCredentials(Vec<CredentialRef>),
41 #[error("something went wrong when generating and storing a new keypackage: {0}")]
42 KeypackageNew(String),
43 #[error(transparent)]
44 Recursive(#[from] crate::RecursiveError),
45}
46
47fn format_invalid_credential_refs(credential_refs: &[CredentialRef]) -> String {
48 credential_refs
49 .iter()
50 .map(|credential_ref| credential_ref.public_key_hash().to_string())
51 .collect::<Vec<_>>()
52 .join(", ")
53}
54
55impl Error {
56 pub fn key_package_new<E: std::error::Error>() -> impl FnOnce(E) -> Self {
57 move |source| Self::KeypackageNew(source.to_string())
58 }
59}