Skip to main content

age_setup/errors/
mod.rs

1pub mod buildings;
2pub mod security;
3pub mod validation;
4pub use buildings::GenerationError;
5pub use security::SecurityError;
6pub use validation::ValidationError;
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    #[error("Key generation failed: {0}")]
10    Generation(#[from] GenerationError),
11    #[error("Validation failed: {0}")]
12    Validation(#[from] ValidationError),
13    #[error("Security operation failed: {0}")]
14    Security(#[from] SecurityError),
15}
16pub type Result<T> = std::result::Result<T, Error>;
17#[cfg(test)]
18mod tests {
19    use super::*;
20    #[test]
21    fn test_error_from_generation() {
22        let gen_err = GenerationError::IdentityCreationFailed;
23        let err: Error = gen_err.into();
24        assert!(matches!(err, Error::Generation(_)));
25    }
26    #[test]
27    fn test_error_from_validation() {
28        let val_err = ValidationError::invalid_public_key("test");
29        let err: Error = val_err.into();
30        assert!(matches!(err, Error::Validation(_)));
31    }
32    #[test]
33    fn test_error_from_security() {
34        let sec_err = SecurityError::MemoryWipeFailed;
35        let err: Error = sec_err.into();
36        assert!(matches!(err, Error::Security(_)));
37    }
38    #[test]
39    fn test_error_display() {
40        let err = Error::Generation(GenerationError::IdentityCreationFailed);
41        assert_eq!(
42            format!("{}", err),
43            "Key generation failed: Age identity generation failed: internal library error"
44        );
45    }
46}