pub struct CipherState<C: Cipher> { /* private fields */ }
Expand description

A CipherState can encrypt and decrypt data.

Mostly like CipherState in the spec, but must be created with a key.

Panics

Encryption and decryption methods will panic if nonce reaches maximum u64, i.e., 2 ^ 64 - 1.

Implementations

Name of cipher, e.g. “ChaChaPoly”.

Create a new CipherState with a key and a nonce n.

Rekey. Set our key to REKEY(old key).

AEAD encryption.

AEAD decryption.

Encryption.

Encryption, returns ciphertext as Vec<u8>.

Decryption.

Decryption, returns plaintext as Vec<u8>.

Get the next value of n. Could be used to decide on whether to re-key, etc.

Get underlying cipher and nonce.

This is useful for e.g. WireGuard. Because packets may be lost or arrive out of order, they would likely want to deal with nonces themselves.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.