[][src]Trait crypto_api::cipher::Cipher

pub trait Cipher: SecKeyGen {
    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>>; }

A stateless (oneshot) cipher interface

Required methods

fn info(&self) -> CipherInfo

Returns information about the cipher

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

Predicts the maximum encrypted length for plaintext_len bytes

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

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

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

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

Loading content...

Implementors

Loading content...