Skip to main content

age_setup/
errors.rs

1use thiserror::Error;
2#[derive(Debug, Error)]
3pub enum Error {
4    #[error("Key generation failed: {0}")]
5    Generation(#[from] GenerationError),
6    #[error("Validation failed: {0}")]
7    Validation(#[from] ValidationError),
8    #[error("Security operation failed: {0}")]
9    Security(#[from] SecurityError),
10}
11pub type Result<T> = std::result::Result<T, Error>;
12#[derive(Debug, Error)]
13pub enum GenerationError {
14    #[error("Identity generation failed")]
15    IdentityCreationFailed,
16}
17#[derive(Debug, Error)]
18pub enum ValidationError {
19    #[error("Invalid public key format: {reason}")]
20    InvalidPublicKeyFormat { reason: String },
21    #[error("Invalid secret key format: {reason}")]
22    InvalidSecretKeyFormat { reason: String },
23}
24impl ValidationError {
25    pub(crate) fn invalid_public_key(reason: impl Into<String>) -> Self {
26        Self::InvalidPublicKeyFormat {
27            reason: reason.into(),
28        }
29    }
30    pub(crate) fn invalid_secret_key(reason: impl Into<String>) -> Self {
31        Self::InvalidSecretKeyFormat {
32            reason: reason.into(),
33        }
34    }
35}
36#[derive(Debug, Error)]
37pub enum SecurityError {
38    #[error("Memory wipe failed")]
39    MemoryWipeFailed,
40}