Skip to main content

AeadCipher

Trait AeadCipher 

Source
pub trait AeadCipher {
    type Algorithm: AeadAlgorithm;
    type Key: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize;

    // Required methods
    fn new(key: &Self::Key) -> Result<Self>
       where Self: Sized;
    fn encrypt(&self) -> impl AeadEncryptOperation<'_, Self::Algorithm>;
    fn decrypt(&self) -> impl AeadDecryptOperation<'_, Self::Algorithm>;
    fn generate_key<R: RngCore + CryptoRng>(rng: &mut R) -> Result<Self::Key>;
    fn generate_nonce<R: RngCore + CryptoRng>(rng: &mut R) -> Result<Nonce<12>>;

    // Provided methods
    fn name() -> &'static str { ... }
    fn key_size() -> usize { ... }
    fn tag_size() -> usize { ... }
}
Expand description

Trait for AEAD ciphers with improved type safety

Required Associated Types§

Source

type Algorithm: AeadAlgorithm

The algorithm this cipher implements

Source

type Key: AsRef<[u8]> + AsMut<[u8]> + Clone + Zeroize

Key type with appropriate size guarantee

Required Methods§

Source

fn new(key: &Self::Key) -> Result<Self>
where Self: Sized,

Creates a new AEAD cipher instance

Source

fn encrypt(&self) -> impl AeadEncryptOperation<'_, Self::Algorithm>

Begin encryption operation with operation pattern

Source

fn decrypt(&self) -> impl AeadDecryptOperation<'_, Self::Algorithm>

Begin decryption operation with operation pattern

Source

fn generate_key<R: RngCore + CryptoRng>(rng: &mut R) -> Result<Self::Key>

Generate a random key

Source

fn generate_nonce<R: RngCore + CryptoRng>(rng: &mut R) -> Result<Nonce<12>>

Generate a random nonce for ChaCha20Poly1305

Provided Methods§

Source

fn name() -> &'static str

Returns the cipher name

Source

fn key_size() -> usize

Returns the key size in bytes

Source

fn tag_size() -> usize

Returns the tag size in bytes

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§