use thiserror::Error;
#[derive(Debug, Error)]
pub enum PaserkError {
#[error("Invalid PASERK format")]
InvalidFormat,
#[error("Invalid PASERK header")]
InvalidHeader,
#[error("Invalid or unsupported PASERK version")]
InvalidVersion,
#[error("Invalid key material")]
InvalidKey,
#[error("Decryption failed")]
DecryptionFailed,
#[error("Authentication failed")]
AuthenticationFailed,
#[error("Key derivation failed")]
KeyDerivationFailed,
#[error("Base64 decode error: {0}")]
Base64Decode(#[from] base64::DecodeError),
#[error("Unsupported wrap protocol: {0}")]
UnsupportedProtocol(String),
#[error("Cryptographic operation failed")]
CryptoError,
}
pub type PaserkResult<T> = Result<T, PaserkError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = PaserkError::InvalidFormat;
assert_eq!(err.to_string(), "Invalid PASERK format");
let err = PaserkError::InvalidHeader;
assert_eq!(err.to_string(), "Invalid PASERK header");
let err = PaserkError::InvalidVersion;
assert_eq!(err.to_string(), "Invalid or unsupported PASERK version");
let err = PaserkError::InvalidKey;
assert_eq!(err.to_string(), "Invalid key material");
let err = PaserkError::DecryptionFailed;
assert_eq!(err.to_string(), "Decryption failed");
let err = PaserkError::AuthenticationFailed;
assert_eq!(err.to_string(), "Authentication failed");
let err = PaserkError::KeyDerivationFailed;
assert_eq!(err.to_string(), "Key derivation failed");
let err = PaserkError::UnsupportedProtocol("custom".to_string());
assert_eq!(err.to_string(), "Unsupported wrap protocol: custom");
let err = PaserkError::CryptoError;
assert_eq!(err.to_string(), "Cryptographic operation failed");
}
#[test]
fn test_error_debug() {
let err = PaserkError::InvalidFormat;
let debug_str = format!("{err:?}");
assert!(debug_str.contains("InvalidFormat"));
}
}