Skip to main content

Cipher

Trait Cipher 

Source
pub trait Cipher: Send + Sync {
    // Required methods
    fn encrypt(
        &self,
        plaintext: &[u8],
        associated_data: Option<&[u8]>,
    ) -> CryptoResult<Vec<u8>>;
    fn decrypt(
        &self,
        ciphertext: &[u8],
        associated_data: Option<&[u8]>,
    ) -> CryptoResult<Vec<u8>>;
    fn algorithm(&self) -> &'static str;
    fn key_size(&self) -> usize;
    fn nonce_size(&self) -> usize;
    fn tag_size(&self) -> usize;
}
Expand description

Trait for symmetric encryption ciphers.

Implementors provide authenticated encryption with associated data (AEAD).

Required Methods§

Source

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

Encrypt plaintext with optional associated data.

Returns the ciphertext with embedded nonce and authentication tag.

Source

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

Decrypt ciphertext with optional associated data.

The ciphertext must include the nonce and authentication tag.

Source

fn algorithm(&self) -> &'static str

Get the cipher algorithm name.

Source

fn key_size(&self) -> usize

Get the key size in bytes.

Source

fn nonce_size(&self) -> usize

Get the nonce size in bytes.

Source

fn tag_size(&self) -> usize

Get the authentication tag size in bytes.

Implementors§

Source§

impl Cipher for Aes256GcmCipher

Available on crate feature aes only.