Skip to main content

Cipher

Trait Cipher 

Source
pub trait Cipher: SecKeyGen {
    // Required methods
    fn info(&self) -> CipherInfo;
    fn encrypted_len_max(&self, plaintext_len: usize) -> usize;
    fn encrypt(
        &self,
        buf: &mut [u8],
        plaintext_len: usize,
        key: &[u8],
        nonce: &[u8],
    ) -> Result<usize, Box<dyn Error + 'static>>;
    fn encrypt_to(
        &self,
        buf: &mut [u8],
        plaintext: &[u8],
        key: &[u8],
        nonce: &[u8],
    ) -> Result<usize, Box<dyn Error + 'static>>;
    fn decrypt(
        &self,
        buf: &mut [u8],
        ciphertext_len: usize,
        key: &[u8],
        nonce: &[u8],
    ) -> Result<usize, Box<dyn Error + 'static>>;
    fn decrypt_to(
        &self,
        buf: &mut [u8],
        ciphertext: &[u8],
        key: &[u8],
        nonce: &[u8],
    ) -> Result<usize, Box<dyn Error + 'static>>;
}
Expand description

A stateless (oneshot) cipher interface

Required Methods§

Source

fn info(&self) -> CipherInfo

Returns information about the cipher

Source

fn encrypted_len_max(&self, plaintext_len: usize) -> usize

Predicts the maximum encrypted length for plaintext_len bytes

Source

fn encrypt( &self, buf: &mut [u8], plaintext_len: usize, key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Encrypts plaintext_len bytes in-place in buf using key and nonce and returns the ciphertext length

Source

fn encrypt_to( &self, buf: &mut [u8], plaintext: &[u8], key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Encrypts plaintext into buf using key and nonce and returns the ciphertext length

Source

fn decrypt( &self, buf: &mut [u8], ciphertext_len: usize, key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Decrypts ciphertext_len bytes in-place in buf using key and nonce and returns the plaintext length

Source

fn decrypt_to( &self, buf: &mut [u8], ciphertext: &[u8], key: &[u8], nonce: &[u8], ) -> Result<usize, Box<dyn Error + 'static>>

Decrypts ciphertext into buf using key and nonce and returns the plaintext length

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§