Skip to main content

mockforge_security_core/
error.rs

1//! Error types for MockForge Security Core
2
3/// Result type alias for security operations
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Error types for security operations
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// Generic error with message string
10    #[error("Security error: {0}")]
11    Generic(String),
12
13    /// I/O error
14    #[error("IO error: {0}")]
15    Io(#[from] std::io::Error),
16
17    /// JSON serialization/deserialization error
18    #[error("JSON error: {0}")]
19    Json(#[from] serde_json::Error),
20
21    /// Encryption error
22    #[error("Encryption error: {0}")]
23    Encryption(#[from] crate::encryption::EncryptionError),
24}
25
26impl Error {
27    /// Create a generic error
28    pub fn generic<S: Into<String>>(message: S) -> Self {
29        Self::Generic(message.into())
30    }
31}
32
33impl From<String> for Error {
34    fn from(message: String) -> Self {
35        Self::Generic(message)
36    }
37}