core_crypto/error/
proteus.rs1pub type ProteusError = super::wrapper::WrappedContextualError<ProteusErrorKind>;
19
20#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
22pub enum ProteusErrorKind {
23 #[cfg(feature = "proteus")]
24 #[error(transparent)]
25 ProteusDecodeError(#[from] proteus_wasm::DecodeError),
27 #[cfg(feature = "proteus")]
28 #[error(transparent)]
29 ProteusEncodeError(#[from] proteus_wasm::EncodeError),
31 #[cfg(feature = "proteus")]
32 #[error(transparent)]
33 ProteusInternalError(#[from] proteus_wasm::error::ProteusError),
35 #[cfg(feature = "proteus")]
36 #[error(transparent)]
37 ProteusSessionError(#[from] proteus_wasm::session::Error<core_crypto_keystore::CryptoKeystoreError>),
39 #[cfg(feature = "proteus")]
41 #[error("{0}")]
42 Leaf(#[from] crate::LeafError),
43}
44
45impl ProteusErrorKind {
46 #[cfg(feature = "proteus")]
47 fn proteus_error_code(&self) -> Option<proteus_traits::ProteusErrorKind> {
48 use proteus_traits::ProteusErrorCode as _;
49 let mut out = match self {
50 ProteusErrorKind::ProteusDecodeError(decode_error) => Some(decode_error.code()),
51 ProteusErrorKind::ProteusEncodeError(encode_error) => Some(encode_error.code()),
52 ProteusErrorKind::ProteusInternalError(proteus_error) => Some(proteus_error.code()),
53 ProteusErrorKind::ProteusSessionError(session_error) => Some(session_error.code()),
54 ProteusErrorKind::Leaf(_) => None,
55 };
56 if out == Some(proteus_traits::ProteusErrorKind::None) {
57 out = None;
58 }
59 out
60 }
61 pub fn error_code(&self) -> Option<u16> {
63 cfg_if::cfg_if! {
64 if #[cfg(feature = "proteus")] {
65 self.proteus_error_code().map(|code| code as u16)
66 } else {
67 None
68 }
69 }
70 }
71}