core_crypto/error/
proteus.rs1pub type ProteusError = super::wrapper::WrappedContextualError<ProteusErrorKind>;
3
4#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
6pub enum ProteusErrorKind {
7 #[cfg(feature = "proteus")]
8 #[error(transparent)]
9 ProteusDecodeError(#[from] proteus_wasm::DecodeError),
11 #[cfg(feature = "proteus")]
12 #[error(transparent)]
13 ProteusEncodeError(#[from] proteus_wasm::EncodeError),
15 #[cfg(feature = "proteus")]
16 #[error(transparent)]
17 ProteusInternalError(#[from] proteus_wasm::error::ProteusError),
19 #[cfg(feature = "proteus")]
20 #[error(transparent)]
21 ProteusSessionError(#[from] proteus_wasm::session::Error<core_crypto_keystore::CryptoKeystoreError>),
23 #[cfg(feature = "proteus")]
25 #[error("{0}")]
26 Leaf(#[from] crate::LeafError),
27}
28
29impl ProteusErrorKind {
30 #[cfg(feature = "proteus")]
31 fn proteus_error_code(&self) -> Option<proteus_traits::ProteusErrorKind> {
32 use proteus_traits::ProteusErrorCode as _;
33 let mut out = match self {
34 ProteusErrorKind::ProteusDecodeError(decode_error) => Some(decode_error.code()),
35 ProteusErrorKind::ProteusEncodeError(encode_error) => Some(encode_error.code()),
36 ProteusErrorKind::ProteusInternalError(proteus_error) => Some(proteus_error.code()),
37 ProteusErrorKind::ProteusSessionError(session_error) => Some(session_error.code()),
38 ProteusErrorKind::Leaf(_) => None,
39 };
40 if out == Some(proteus_traits::ProteusErrorKind::None) {
41 out = None;
42 }
43 out
44 }
45 pub fn error_code(&self) -> Option<u16> {
47 cfg_if::cfg_if! {
48 if #[cfg(feature = "proteus")] {
49 self.proteus_error_code().map(|code| code as u16)
50 } else {
51 None
52 }
53 }
54 }
55}