Skip to main content

age_setup/errors/
validation.rs

1#[derive(Debug, thiserror::Error)]
2pub enum ValidationError {
3    #[error("Invalid public key format: {reason}")]
4    InvalidPublicKeyFormat { reason: String },
5}
6impl ValidationError {
7    pub(crate) fn invalid_public_key(reason: impl Into<String>) -> Self {
8        Self::InvalidPublicKeyFormat {
9            reason: reason.into(),
10        }
11    }
12}
13#[cfg(test)]
14mod tests {
15    use super::*;
16    #[test]
17    fn test_validation_error_display() {
18        let err = ValidationError::invalid_public_key("test reason");
19        let msg = format!("{}", err);
20        assert_eq!(msg, "Invalid public key format: test reason");
21    }
22}