Skip to main content

KeyProtection

Enum KeyProtection 

Source
#[non_exhaustive]
pub enum KeyProtection { AesKeyWrap, RsaOaepSha256, ProviderDefined, }
Expand description

How a data key was protected, in terms a container can record.

A container names the key-encryption algorithm in its own structure, so the caller has to know which one the backend used. Asking the backend is the only way: the protected bytes say nothing about themselves, and what a device does to protect a key is a property of that device rather than of the request.

Every key-protection API in the field takes this as a parameter on the way back: Azure Key Vault’s unwrapKey requires alg, PKCS#11’s C_UnwrapKey requires a mechanism, and AWS KMS Decrypt requires EncryptionAlgorithm for an asymmetric key. A pair of methods without it only works where one implementation is both ends.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

AesKeyWrap

RFC 3394 AES Key Wrap under a symmetric KEK.

What a CMS KEKRecipientInfo names as id-aes128-wrap or id-aes256-wrap, PKCS#11 as CKM_AES_KEY_WRAP, and Azure as A256KW.

§

RsaOaepSha256

RSAES-OAEP with SHA-256, under a public key.

Azure RSA-OAEP-256, PKCS#11 CKM_RSA_PKCS_OAEP, AWS RSAES_OAEP_SHA_256.

§

ProviderDefined

The provider’s own envelope, which names no algorithm and follows no published format.

AWS KMS is the case to design for. GenerateDataKey returns a CiphertextBlob of up to 6144 bytes for a 32-byte data key, carrying the key ARN and the encryption context beside the key, and the response names no algorithm at all. Only Decrypt against the same service opens it.

A standard container cannot carry one. A CMS KEKRecipientInfo has to declare a key-encryption algorithm, and declaring id-aes256-wrap over a blob that is not an AES key wrap would produce an artifact whose own structure lies about it, which no reader could open and rite verify would report as checked. A step that assembles a container refuses this by name instead.

Implementations§

Source§

impl KeyProtection

Source

pub fn is_nameable_in_a_container(self) -> bool

Whether a standard container can record this protection and a standard reader can therefore open the result.

Matched exhaustively on purpose: a protection added without answering this would otherwise default into being written into a container that cannot describe it.

Trait Implementations§

Source§

impl Clone for KeyProtection

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for KeyProtection

Source§

impl Debug for KeyProtection

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for KeyProtection

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for KeyProtection

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for KeyProtection

Source§

impl PartialEq for KeyProtection

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for KeyProtection

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for KeyProtection

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.