dcrypt_api/error/
mod.rs

1//! Error handling for cryptographic ecosystem
2
3#![cfg_attr(not(feature = "std"), no_std)]
4
5pub mod registry;
6pub mod traits;
7pub mod types;
8pub mod validate;
9
10// Re-export the primary error type and result
11pub use types::{Error, Result};
12
13// Re-export the error registry
14pub use registry::ERROR_REGISTRY;
15
16// Re-export error traits
17pub use traits::{ResultExt, SecureErrorHandling};
18
19// Re-export validation utilities module (not as a nested function)
20pub use validate as validation;
21
22// Standard library error conversions
23#[cfg(feature = "std")]
24impl From<std::array::TryFromSliceError> for Error {
25    fn from(_: std::array::TryFromSliceError) -> Self {
26        Self::InvalidLength {
27            context: "array conversion",
28            expected: 0, // Unknown expected size
29            actual: 0,   // Unknown actual size
30        }
31    }
32}
33
34#[cfg(feature = "std")]
35impl From<std::io::Error> for Error {
36    fn from(e: std::io::Error) -> Self {
37        Self::Other {
38            context: "I/O operation",
39            message: e.to_string(),
40        }
41    }
42}
43
44#[cfg(feature = "std")]
45use std::error::Error as StdError;
46
47// Implement standard Error trait when std is available
48#[cfg(feature = "std")]
49impl StdError for Error {}
50
51// Specialized result types for different operations
52pub type CipherResult<T> = Result<T>;
53pub type HashResult<T> = Result<T>;
54pub type KeyResult<T> = Result<T>;
55pub type SignatureResult<T> = Result<T>;