pub struct Aead { /* private fields */ }Expand description
The Aead struct allows to re-use a key without having to initialize it every time.
Implementations§
source§impl Aead
impl Aead
sourcepub fn new(alg: Algorithm, k: &[u8]) -> Result<Self, Error>
pub fn new(alg: Algorithm, k: &[u8]) -> Result<Self, Error>
Create a new Aead cipher with the given Algorithm alg and key k.
If the algorithm is not supported or the state generation fails, this
function returns an Error.
To get an Aead instance without setting a key immediately see init.
sourcepub fn init(mode: Algorithm) -> Result<Self, Error>
pub fn init(mode: Algorithm) -> Result<Self, Error>
Initialize a new Aead object without a key.
Use set_key to do so later.
sourcepub fn set_key(self, k: &[u8]) -> Result<Self, Error>
pub fn set_key(self, k: &[u8]) -> Result<Self, Error>
Set the key for this instance. This consumes the Aead and returns a new instance with the key.
sourcepub fn set_random_key(&mut self) -> Result<(), Error>
pub fn set_random_key(&mut self) -> Result<(), Error>
Generate a new random key for this instance. This consumes the Aead and returns a new instance with the key.
sourcepub const fn nonce_size(&self) -> usize
pub const fn nonce_size(&self) -> usize
Get the nonce size of this Aead in bytes.
sourcepub fn encrypt(
&self,
msg: &[u8],
iv: &[u8],
aad: &Aad,
) -> Result<(Ciphertext, Vec<u8>), Error>
pub fn encrypt( &self, msg: &[u8], iv: &[u8], aad: &Aad, ) -> Result<(Ciphertext, Vec<u8>), Error>
Encrypt with the algorithm and key of this Aead.
Returns (ctxt, tag) or an Error.
sourcepub fn encrypt_combined(
&self,
msg: &[u8],
iv: &[u8],
aad: &Aad,
) -> Result<Ciphertext, Error>
pub fn encrypt_combined( &self, msg: &[u8], iv: &[u8], aad: &Aad, ) -> Result<Ciphertext, Error>
Encrypt with the algorithm and key of this Aead.
Returns (ctxt || tag) or an Error.
This is more efficient if the tag needs to be appended to the cipher text.
sourcepub fn encrypt_in_place(
&self,
payload: &mut [u8],
iv: &[u8],
aad: &Aad,
) -> Result<Vec<u8>, Error>
pub fn encrypt_in_place( &self, payload: &mut [u8], iv: &[u8], aad: &Aad, ) -> Result<Vec<u8>, Error>
Encrypt with the algorithm and key of this Aead.
Returns the cipher text in the payload and a tag or an Error.
sourcepub fn decrypt(
&self,
ctxt: &[u8],
tag: &[u8],
iv: &[u8],
aad: &Aad,
) -> Result<Vec<u8>, Error>
pub fn decrypt( &self, ctxt: &[u8], tag: &[u8], iv: &[u8], aad: &Aad, ) -> Result<Vec<u8>, Error>
Decrypt with the algorithm and key of this Aead.
Returns msg or an Error.