pub trait CryptoBackend {
// Required methods
fn encrypt(
&self,
key: &[u8],
nonce: &[u8],
aad: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>, CryptoError>;
fn decrypt(
&self,
key: &[u8],
nonce: &[u8],
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>, CryptoError>;
fn generate_key(&self) -> Vec<u8> ⓘ;
fn generate_nonce(&self) -> Vec<u8> ⓘ;
}Expand description
Trait abstracting symmetric encryption operations.
Implementors provide authenticated encryption with associated data (AEAD).
The base crate ships a MockCryptoBackend for testing. Real
implementations (e.g. AES-256-GCM) can be provided behind feature flags.
Required Methods§
Sourcefn encrypt(
&self,
key: &[u8],
nonce: &[u8],
aad: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>, CryptoError>
fn encrypt( &self, key: &[u8], nonce: &[u8], aad: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Encrypt plaintext using key, nonce, and aad.
Sourcefn decrypt(
&self,
key: &[u8],
nonce: &[u8],
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>, CryptoError>
fn decrypt( &self, key: &[u8], nonce: &[u8], aad: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Decrypt ciphertext using key, nonce, and aad.
Sourcefn generate_key(&self) -> Vec<u8> ⓘ
fn generate_key(&self) -> Vec<u8> ⓘ
Generate a fresh encryption key.
Sourcefn generate_nonce(&self) -> Vec<u8> ⓘ
fn generate_nonce(&self) -> Vec<u8> ⓘ
Generate a fresh nonce.