scsys_crypto/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: @FL03
4*/
5/// a type alias for a [`Result`] type configured to use the [`CryptoError`] type
6pub type CryptoResult<T = ()> = core::result::Result<T, CryptoError>;
7/// a custom error type for the `scsys-crypto` crate
8#[derive(Debug, thiserror::Error)]
9pub enum CryptoError {
10    #[cfg(feature = "anyhow")]
11    #[error(transparent)]
12    AnyError(#[from] anyhow::Error),
13    #[cfg(feature = "alloc")]
14    #[error(transparent)]
15    BoxError(#[from] alloc::boxed::Box<dyn core::error::Error + Send + Sync + 'static>),
16    #[cfg(feature = "std")]
17    #[error(transparent)]
18    IoError(#[from] std::io::Error),
19    #[cfg(feature = "json")]
20    #[error(transparent)]
21    JsonError(#[from] serde_json::Error),
22    #[cfg(feature = "alloc")]
23    #[error("Unknown error: {0}")]
24    Unknown(alloc::string::String),
25}
26
27#[cfg(feature = "alloc")]
28impl From<alloc::string::String> for CryptoError {
29    fn from(value: alloc::string::String) -> Self {
30        Self::Unknown(value)
31    }
32}
33
34#[cfg(feature = "alloc")]
35impl From<&str> for CryptoError {
36    fn from(value: &str) -> Self {
37        Self::Unknown(value.to_string())
38    }
39}