Trait BlockCipherMode

Source
pub trait BlockCipherMode<C: BlockCipher> {
    type Mode: CipherMode;
    type Nonce: AsRef<[u8]> + AsMut<[u8]> + Clone;

    // Required methods
    fn new(cipher: C, nonce: &Self::Nonce) -> Result<Self>
       where Self: Sized;
    fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>;
    fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>;
    fn generate_nonce<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Nonce;

    // Provided method
    fn mode_name() -> &'static str { ... }
}
Expand description

Trait for block cipher modes with type parameters

Required Associated Types§

Source

type Mode: CipherMode

The mode this implementation uses

Source

type Nonce: AsRef<[u8]> + AsMut<[u8]> + Clone

Nonce/IV type with appropriate size constraint

Required Methods§

Source

fn new(cipher: C, nonce: &Self::Nonce) -> Result<Self>
where Self: Sized,

Creates a new block cipher mode instance

Source

fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>

Encrypts plaintext data

Source

fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>

Decrypts ciphertext data

Source

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

Generate a random nonce

Provided Methods§

Source

fn mode_name() -> &'static str

Returns the mode name

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§