Skip to main content

dcrypt_api/error/
mod.rs

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