Skip to main content

AEADCipher

Trait AEADCipher 

Source
pub trait AEADCipher: Send + Sync {
    // Required methods
    fn encrypt(
        &self,
        key: &[u8; 32],
        nonce: &[u8; 24],
        plaintext: &[u8],
        aad: &[u8],
    ) -> Result<Zeroizing<Vec<u8>>, AEADError>;
    fn decrypt(
        &self,
        key: &[u8; 32],
        nonce: &[u8; 24],
        ciphertext: &[u8],
        aad: &[u8],
    ) -> Result<Zeroizing<Vec<u8>>, AEADError>;
}
Expand description

Authenticated encryption with associated data.

Abstracted behind a trait so the pipeline depends on the operation and not on the concrete cipher. Send + Sync because a single cipher value is shared by reference across the pipeline’s worker threads.

Required Methods§

Source

fn encrypt( &self, key: &[u8; 32], nonce: &[u8; 24], plaintext: &[u8], aad: &[u8], ) -> Result<Zeroizing<Vec<u8>>, AEADError>

Encrypts plaintext under key and nonce, binding aad to the tag.

The returned buffer is the ciphertext with the 16-byte Poly1305 tag appended, and it is wiped when dropped.

§Errors

Returns AEADError::CipherError if the underlying cipher fails.

Source

fn decrypt( &self, key: &[u8; 32], nonce: &[u8; 24], ciphertext: &[u8], aad: &[u8], ) -> Result<Zeroizing<Vec<u8>>, AEADError>

Decrypts and authenticates ciphertext, which must carry its trailing tag and must have been produced with the same aad.

§Errors

Returns AEADError::AuthenticationFailed, and nothing else. Every internal cause — invalid tag, wrong key, truncated input — is collapsed into that single variant, because distinguishing them would hand an attacker an oracle that tells them why their guess was rejected.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§