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§
Sourcefn info(&self) -> CipherInfo
fn info(&self) -> CipherInfo
Returns information about the cipher
Sourcefn encrypted_len_max(&self, plaintext_len: usize) -> usize
fn encrypted_len_max(&self, plaintext_len: usize) -> usize
Predicts the maximum encrypted length for plaintext_len bytes
Sourcefn encrypt(
&self,
buf: &mut [u8],
plaintext_len: usize,
key: &[u8],
nonce: &[u8],
) -> Result<usize, Box<dyn Error + 'static>>
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
Sourcefn encrypt_to(
&self,
buf: &mut [u8],
plaintext: &[u8],
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>>
Encrypts plaintext into buf using key and nonce and returns the ciphertext length
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".