Skip to main content

Key

Struct Key 

Source
pub struct Key { /* private fields */ }
Expand description

An AEAD key the profile admits. It seals under nonces the crate chooses, never the caller’s: AES-GCM’s is drawn inside the module’s seal, ChaCha20-Poly1305’s from the module’s DRBG just before its seal. It refuses its 2^32 + 1th seal with CryptoError::AeadLimit. It opens under the nonce stored beside a ciphertext. It is not Clone, so its seal count cannot be copied. Its key schedule is held in the module’s AEAD contexts, which the module clears on drop.

Implementations§

Source§

impl Key

Source

pub fn new( a: &Admitted, algorithm: AeadAlgorithm, key: &[u8], ) -> Result<Key, CryptoError>

A key for algorithm. Refuses, in order: an algorithm a’s profile does not admit or its module line lacks (Admitted::admit_aead); a key that is not algorithm.key_len() bytes (CryptoError::AeadKeyLength); a key the module refuses (CryptoError::AeadKey).

Source

pub fn algorithm(&self) -> AeadAlgorithm

The algorithm.

Source

pub fn seal_in_place( &self, aad: &[u8], buf: &mut [u8], ) -> Result<([u8; 12], [u8; 16]), CryptoError>

Encrypts buf in place and returns the nonce and the tag, which the caller stores beside the ciphertext. AES-GCM draws the nonce inside the module’s seal (FIPS 140-3 IG C.H Scenario 2); ChaCha20-Poly1305 draws it from the module’s DRBG. Refuses, in order: a plaintext longer than algorithm.max_plaintext_len() (CryptoError::AeadPlaintextLength); a 2^32 + 1th seal (CryptoError::AeadLimit); a module failure (CryptoError::AeadSeal, or CryptoError::Random). A seal the module refuses after reserving its invocation still counts toward the limit; an AeadLimit refusal reserves nothing.

Source

pub fn open_in_place<'b>( &self, nonce: &[u8; 12], aad: &[u8], buf: &'b mut [u8], ) -> Result<&'b mut [u8], CryptoError>

Authenticates and decrypts buf, the ciphertext followed by its tag, in place, and returns the plaintext prefix. Refuses a buffer shorter than the tag, and anything that does not authenticate under this key, nonce and aad, with CryptoError::AeadOpen. Opening does not count toward the seal limit.

Trait Implementations§

Source§

impl Debug for Key

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Key

§

impl Forget for Key

§

impl Move for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnsafeUnpin for Key

§

impl UnwindSafe for Key

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.