Skip to main content

SymmetricCryptoKey

Enum SymmetricCryptoKey 

pub enum SymmetricCryptoKey {
    Aes256CbcKey(Aes256CbcKey),
    Aes256CbcHmacKey(Aes256CbcHmacKey),
    XChaCha20Poly1305Key(XChaCha20Poly1305Key),
    Aes256GcmKey(Aes256GcmKey),
    XAes256GcmKey(XAes256GcmKey),
}
Expand description

The key type an Unlocked holds, re-exported so a caller building one for a test can name it. A symmetric encryption key. Used to encrypt and decrypt EncString

Variants§

§

Aes256CbcKey(Aes256CbcKey)

§

Aes256CbcHmacKey(Aes256CbcHmacKey)

§

XChaCha20Poly1305Key(XChaCha20Poly1305Key)

Data encrypted by XChaCha20Poly1305Key keys has type Cose_Encrypt0_B64

§

Aes256GcmKey(Aes256GcmKey)

FIPS-approved AES-256-GCM key, used as the content-encryption key for FIPS DataEnvelopes. Encoded as a COSE key.

§

XAes256GcmKey(XAes256GcmKey)

Extended-nonce AES-256-GCM key. Encoded as a COSE key and used with type-7 EncStrings.

Implementations§

§

impl SymmetricCryptoKey

pub fn make(algorithm: SymmetricKeyAlgorithm) -> SymmetricCryptoKey

Make a new SymmetricCryptoKey for the specified algorithm

pub fn to_encoded(&self) -> Bytes<BitwardenLegacyKeyContentFormat>

Encodes the key to a byte array representation, that is separated by size. SymmetricCryptoKey::Aes256CbcHmacKey and SymmetricCryptoKey::Aes256CbcKey are encoded as 64 and 32 bytes respectively. COSE-serialized variants are encoded as at least 65 bytes using padding.

This can be used for storage and transmission in the old byte array format. When the wrapping key is a COSE key, and the wrapped key is a COSE key, then this should not use the byte representation but instead use the COSE key representation.

pub fn to_base64(&self) -> B64

pub fn key_id(&self) -> Option<KeyId>

Returns the key ID of the key, if it has one. Every authenticated key variant has a key ID; only the unauthenticated SymmetricCryptoKey::Aes256CbcKey does not.

SymmetricCryptoKey::Aes256CbcHmacKey has no field to store a key ID in, and derives one from its key material instead: its RFC 9679 thumbprint, truncated to the key ID length. Two such keys with identical key material therefore share an ID.

Trait Implementations§

§

impl Clone for SymmetricCryptoKey

§

fn clone(&self) -> SymmetricCryptoKey

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
§

impl ConstantTimeEq for SymmetricCryptoKey

§

fn ct_eq(&self, other: &SymmetricCryptoKey) -> Choice

Note: This is constant time with respect to comparing two keys of the same type, but not constant type with respect to the fact that different keys are compared. If two types of different keys are compared, then this does have different timing.

Source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
§

impl CoseKeyThumbprintExt for SymmetricCryptoKey

§

fn thumbprint(&self) -> Result<CoseKeyThumbprint, CryptoError>

Computes the RFC 9679 thumbprint of this symmetric key.

Returns an error for the unauthenticated legacy AES-CBC key, which is not representable as a COSE key.

§

impl CryptoKey for SymmetricCryptoKey

§

impl Debug for SymmetricCryptoKey

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for SymmetricCryptoKey

§

fn deserialize<D>( deserializer: D, ) -> Result<SymmetricCryptoKey, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

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

impl Drop for SymmetricCryptoKey

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl FromStr for SymmetricCryptoKey

§

type Err = CryptoError

The associated error which can be returned from parsing.
§

fn from_str( s: &str, ) -> Result<SymmetricCryptoKey, <SymmetricCryptoKey as FromStr>::Err>

Parses a string s to return a value of this type. Read more
§

impl KeyEncryptable<PinKey, EncString> for &SymmetricCryptoKey

§

fn encrypt_with_key(self, key: &PinKey) -> Result<EncString, CryptoError>

Encrypts a value using the provided key reference.
§

impl PartialEq for SymmetricCryptoKey

§

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

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

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

Inequality operator !=. Read more
§

impl Serialize for SymmetricCryptoKey

§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

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

impl TryFrom<&Bytes<BitwardenLegacyKeyContentFormat>> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from( value: &Bytes<BitwardenLegacyKeyContentFormat>, ) -> Result<SymmetricCryptoKey, <SymmetricCryptoKey as TryFrom<&Bytes<BitwardenLegacyKeyContentFormat>>>::Error>

Performs the conversion.
§

impl TryFrom<&CoseKey> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from( cose_key: &CoseKey, ) -> Result<SymmetricCryptoKey, <SymmetricCryptoKey as TryFrom<&CoseKey>>::Error>

Performs the conversion.
§

impl TryFrom<B64> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from( value: B64, ) -> Result<SymmetricCryptoKey, <SymmetricCryptoKey as TryFrom<B64>>::Error>

Performs the conversion.
§

impl TryFrom<EncodedSymmetricKey> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from( value: EncodedSymmetricKey, ) -> Result<SymmetricCryptoKey, <SymmetricCryptoKey as TryFrom<EncodedSymmetricKey>>::Error>

Performs the conversion.
§

impl TryFrom<String> for SymmetricCryptoKey

§

type Error = CryptoError

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

fn try_from( value: String, ) -> Result<SymmetricCryptoKey, <SymmetricCryptoKey as TryFrom<String>>::Error>

Performs the conversion.

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, 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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more