use thiserror::Error; #[derive(Debug, Error)] pub enum CryptError { #[error("envelope prefix `{0}` is not recognized")] EnvelopePrefix(String), #[error("envelope is truncated")] EnvelopeTruncated, #[error("envelope version {0} is not supported")] UnsupportedVersion(u8), #[error("envelope algorithm {0} is not supported")] UnsupportedAlgorithm(u8), #[error("envelope key id is not valid utf-8")] KeyIdEncoding, #[error("base64 decode failed: {0}")] Base64(String), #[error("pem material is not valid utf-8")] PemEncoding, #[error("pem parse failed: {0}")] Pem(String), #[error("rsa operation failed: {0}")] Rsa(String), #[error("rsa key size {0} is below the minimum {1}")] KeySize(usize, usize), #[error("rsa key is smaller than the wrapped key")] WrappedKeyTooLarge, #[error("aes-gcm operation failed")] Aead, #[error("plaintext is not valid utf-8")] Utf8(#[from] std::string::FromUtf8Error), #[error("decryption key `{0}` is not configured")] KeyNotFound(String), #[error("no decryption key is configured")] NoKeys, #[error("public key does not match the private key")] KeyMismatch, #[error("app config: {0}")] Config(String), #[error("io failure: {0}")] Io(#[from] std::io::Error), } pub type CryptResult = Result;