pub enum Error {
Encrypt(EncryptError),
Decrypt(DecryptError),
}Expand description
The universal error type for this crate.
This enum represents every possible error that a function in this library can return. It is a thin wrapper around the domain‑specific error types:
EncryptErrorfor encryption‑related failures.DecryptErrorfor decryption‑related failures.
The #[from] attribute generates From<EncryptError> and
From<DecryptError> implementations, so conversions are automatic
(see module documentation for details). This keeps the
public API clean – all functions return a single error type, yet
callers can still inspect the underlying cause.
§Display format
Each variant prefixes the error message with the domain:
Encrypt error: Invalid recipient 'abc': reason
Decrypt error: Invalid identity: something§Example of error propagation with ?
use age_crypto::{encrypt_with_passphrase, Error};
fn safe_encrypt(plaintext: &[u8], passphrase: &str) -> Result<Vec<u8>, Error> {
// encrypt_with_passphrase already returns Result<_, Error>
// so we can use `?` directly for propagation
let encrypted = encrypt_with_passphrase(plaintext, passphrase)?;
Ok(encrypted.as_bytes().to_vec())
}Variants§
Encrypt(EncryptError)
An encryption‑related error occurred.
The inner EncryptError provides detailed information about
missing recipients, invalid keys, or internal failures.
Decrypt(DecryptError)
A decryption‑related error occurred.
The inner DecryptError provides detailed information about
invalid identities, broken ciphertext, or decryption mismatches.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()