use async_trait::async_trait;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum EncryptorError {
#[error("wrong key version: {0}")]
WrongKeyVersion(u8),
#[error("encryption failed: {0}")]
EncryptionFailed(String),
#[error("decryption failed: {0}")]
DecryptionFailed(String),
#[error("missing nonce")]
MissingNonce,
#[cfg(feature = "aws-kms")]
#[error("KMS error: {0}")]
Kms(Box<dyn std::error::Error + Send + Sync + 'static>),
}
#[derive(Clone)]
pub struct Encrypted {
pub ciphertext: Vec<u8>,
pub nonce: Option<[u8; 12]>,
pub key_version: u8,
}
#[async_trait]
pub trait KeyEncryptor: Send + Sync + 'static {
async fn encrypt(&self, plaintext: &[u8]) -> Result<Encrypted, EncryptorError>;
async fn decrypt(&self, encrypted: &Encrypted) -> Result<Vec<u8>, EncryptorError>;
}