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 validation utilities module (not as a nested function)
12pub use validate as validation;
13
14// Standard library error conversions
15#[cfg(feature = "std")]
16impl From<std::array::TryFromSliceError> for Error {
17    fn from(_: std::array::TryFromSliceError) -> Self {
18        Self::InvalidLength {
19            context: "array conversion",
20            expected: 0, // Unknown expected size
21            actual: 0,   // Unknown actual size
22        }
23    }
24}
25
26#[cfg(feature = "std")]
27impl From<std::io::Error> for Error {
28    fn from(e: std::io::Error) -> Self {
29        Self::Other {
30            context: "I/O operation",
31            message: e.to_string(),
32        }
33    }
34}
35
36#[cfg(feature = "std")]
37use std::error::Error as StdError;
38
39// Implement standard Error trait when std is available
40#[cfg(feature = "std")]
41impl StdError for Error {}
42
43// Specialized result types for different operations
44pub type CipherResult<T> = Result<T>;
45pub type HashResult<T> = Result<T>;
46pub type KeyResult<T> = Result<T>;
47pub type SignatureResult<T> = Result<T>;