use async_trait::async_trait;
#[async_trait]
pub trait EncryptionProvider {
type Error: std::error::Error + Send + Sync + 'static;
async fn encrypt(&self, plain: Vec<Vec<u8>>) -> Result<Vec<Vec<u8>>, Self::Error>;
async fn decrypt(&self, cipher: Vec<Vec<u8>>) -> Result<Vec<Vec<u8>>, Self::Error>;
fn max_batch_size(&self) -> usize;
}
#[derive(Clone)]
pub struct NoEncryption;
#[async_trait]
impl EncryptionProvider for NoEncryption {
type Error = NoEncryptionError;
async fn encrypt(&self, plain: Vec<Vec<u8>>) -> Result<Vec<Vec<u8>>, Self::Error> {
Ok(plain)
}
async fn decrypt(&self, cipher: Vec<Vec<u8>>) -> Result<Vec<Vec<u8>>, Self::Error> {
Ok(cipher)
}
fn max_batch_size(&self) -> usize {
100
}
}
#[derive(Debug)]
pub struct NoEncryptionError;
impl std::fmt::Display for NoEncryptionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "NoEncryptionError")
}
}
impl std::error::Error for NoEncryptionError {}