Skip to main content

DataKey

Struct DataKey 

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

A content-encryption key in the two forms envelope encryption needs.

The plaintext is for the caller to encrypt with and drop. The wrapped copy is what the container carries, and only the key-encryption key that produced it opens that again.

This is what every key-protection device offers instead of a cipher: AWS KMS calls it GenerateDataKey, PKCS#11 reaches it with C_GenerateKey followed by C_WrapKey. The content never crosses the boundary, so a device that protects a key it will not export does not also have to be fast enough to encrypt a file.

Implementations§

Source§

impl DataKey

Source

pub fn new( plaintext: Zeroizing<Vec<u8>>, wrapped: Vec<u8>, protection: KeyProtection, ) -> Self

Pair a fresh data key with the copy its protector can open, and with what protected it.

Source

pub fn plaintext(&self) -> &[u8] ⓘ

The key itself, to encrypt content with.

Source

pub fn wrapped(&self) -> &[u8] ⓘ

The same key, protected. This is what goes into the container.

Source

pub fn protection(&self) -> KeyProtection

What protected it, which is what a container has to declare and what opening it again needs.

Trait Implementations§

Source§

impl Debug for DataKey

Source§

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

Names the shape and never the key. A data key is a secret with a short life, and a debug print is the way such a thing ends up in a log.

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.