pub enum SymmetricCryptoKey {
Aes256CbcKey(Aes256CbcKey),
Aes256CbcHmacKey(Aes256CbcHmacKey),
XChaCha20Poly1305Key(XChaCha20Poly1305Key),
Aes256GcmKey(Aes256GcmKey),
XAes256GcmKey(XAes256GcmKey),
}Expand description
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§
Source§impl SymmetricCryptoKey
impl SymmetricCryptoKey
const AES256_CBC_KEY_LEN: usize = 32
const AES256_CBC_HMAC_KEY_LEN: usize = 64
Sourcepub(crate) fn make_aes256_cbc_hmac_key_internal(rng: impl CryptoRng) -> Self
pub(crate) fn make_aes256_cbc_hmac_key_internal(rng: impl CryptoRng) -> Self
Generate a new random AES256_CBC SymmetricCryptoKey
WARNING: This function should only be used with a proper cryptographic RNG. If you do not have a good reason for using this function, use SymmetricCryptoKey::make_aes256_cbc_hmac_key instead.
Sourcepub fn make(algorithm: SymmetricKeyAlgorithm) -> Self
pub fn make(algorithm: SymmetricKeyAlgorithm) -> Self
Make a new SymmetricCryptoKey for the specified algorithm
Sourcepub(crate) fn make_aes256_cbc_hmac_key() -> Self
pub(crate) fn make_aes256_cbc_hmac_key() -> Self
Generate a new random AES256_CBC_HMAC SymmetricCryptoKey
Sourcepub(crate) fn make_xchacha20_poly1305_key() -> Self
pub(crate) fn make_xchacha20_poly1305_key() -> Self
Generate a new random XChaCha20Poly1305 SymmetricCryptoKey
Sourcepub fn to_encoded(&self) -> BitwardenLegacyKeyBytes
pub fn to_encoded(&self) -> BitwardenLegacyKeyBytes
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.
Sourcepub(crate) fn to_encoded_raw(&self) -> EncodedSymmetricKey
pub(crate) fn to_encoded_raw(&self) -> EncodedSymmetricKey
Creates the byte representation of the key, without any padding. This should not be used directly for creating serialized key representations, instead, SymmetricCryptoKey::to_encoded should be used.
SymmetricCryptoKey::Aes256CbcHmacKey and SymmetricCryptoKey::Aes256CbcKey are encoded as 64 and 32 byte arrays respectively, representing the key bytes directly. XChaCha20-Poly1305, AES-256-GCM, and XAES-256-GCM keys are encoded as serialized COSE keys. A COSE key can be directly encrypted with a COSE key content format or represented as a byte array. When represented as a byte array, the array is padded to be larger than the byte array representation of the other aforementioned key types.
pub(crate) fn try_from_cose(serialized_key: &[u8]) -> Result<Self, CryptoError>
pub fn to_base64(&self) -> B64
Sourcepub fn key_id(&self) -> Option<KeyId>
pub fn key_id(&self) -> Option<KeyId>
Returns the key ID of the key, if it has one. COSE-serialized key variants have a key ID.
Sourcepub(crate) fn as_cose_key_view(&self) -> Option<CoseKeyView<'_>>
pub(crate) fn as_cose_key_view(&self) -> Option<CoseKeyView<'_>>
Returns a CoseKeyView for COSE-encoded symmetric key variants.
Legacy AES-CBC variants return None.
Trait Implementations§
Source§impl Clone for SymmetricCryptoKey
impl Clone for SymmetricCryptoKey
Source§fn clone(&self) -> SymmetricCryptoKey
fn clone(&self) -> SymmetricCryptoKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConstantTimeEq for SymmetricCryptoKey
impl ConstantTimeEq for SymmetricCryptoKey
Source§fn ct_eq(&self, other: &SymmetricCryptoKey) -> Choice
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§impl CoseKeyThumbprintExt for SymmetricCryptoKey
impl CoseKeyThumbprintExt for SymmetricCryptoKey
Source§fn thumbprint(&self) -> Result<CoseKeyThumbprint, CryptoError>
fn thumbprint(&self) -> Result<CoseKeyThumbprint, CryptoError>
Computes the RFC 9679 thumbprint of this symmetric key.
Returns an error for legacy AES-CBC keys, which are not currently representable as COSE keys.
Source§impl Debug for SymmetricCryptoKey
impl Debug for SymmetricCryptoKey
Source§impl<'de> Deserialize<'de> for SymmetricCryptoKey
impl<'de> Deserialize<'de> for SymmetricCryptoKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Drop for SymmetricCryptoKey
impl Drop for SymmetricCryptoKey
Source§impl FromStr for SymmetricCryptoKey
impl FromStr for SymmetricCryptoKey
Source§impl FromWasmAbi for SymmetricCryptoKey
Available on crate feature wasm only.
impl FromWasmAbi for SymmetricCryptoKey
wasm only.Source§impl IntoWasmAbi for SymmetricCryptoKey
Available on crate feature wasm only.
impl IntoWasmAbi for SymmetricCryptoKey
wasm only.Source§impl KeyDecryptable<SymmetricCryptoKey, String> for EncString
impl KeyDecryptable<SymmetricCryptoKey, String> for EncString
fn decrypt_with_key( &self, key: &SymmetricCryptoKey, ) -> Result<String, CryptoError>
Source§impl KeyDecryptable<SymmetricCryptoKey, Vec<u8>> for EncString
impl KeyDecryptable<SymmetricCryptoKey, Vec<u8>> for EncString
fn decrypt_with_key( &self, key: &SymmetricCryptoKey, ) -> Result<Vec<u8>, CryptoError>
Source§impl KeyEncryptable<PinKey, EncString> for &SymmetricCryptoKey
impl KeyEncryptable<PinKey, EncString> for &SymmetricCryptoKey
Source§fn encrypt_with_key(self, key: &PinKey) -> Result<EncString, CryptoError>
fn encrypt_with_key(self, key: &PinKey) -> Result<EncString, CryptoError>
Source§impl<T: ConstContentFormat> KeyEncryptable<SymmetricCryptoKey, EncString> for &Bytes<T>
impl<T: ConstContentFormat> KeyEncryptable<SymmetricCryptoKey, EncString> for &Bytes<T>
Source§fn encrypt_with_key(
self,
key: &SymmetricCryptoKey,
) -> Result<EncString, CryptoError>
fn encrypt_with_key( self, key: &SymmetricCryptoKey, ) -> Result<EncString, CryptoError>
Source§impl KeyEncryptable<SymmetricCryptoKey, EncString> for &str
impl KeyEncryptable<SymmetricCryptoKey, EncString> for &str
Source§fn encrypt_with_key(
self,
key: &SymmetricCryptoKey,
) -> Result<EncString, CryptoError>
fn encrypt_with_key( self, key: &SymmetricCryptoKey, ) -> Result<EncString, CryptoError>
Source§impl KeyEncryptable<SymmetricCryptoKey, EncString> for String
impl KeyEncryptable<SymmetricCryptoKey, EncString> for String
Source§fn encrypt_with_key(
self,
key: &SymmetricCryptoKey,
) -> Result<EncString, CryptoError>
fn encrypt_with_key( self, key: &SymmetricCryptoKey, ) -> Result<EncString, CryptoError>
Source§impl KeyEncryptableWithContentType<SymmetricCryptoKey, EncString> for &[u8]
impl KeyEncryptableWithContentType<SymmetricCryptoKey, EncString> for &[u8]
fn encrypt_with_key( self, key: &SymmetricCryptoKey, content_format: ContentFormat, ) -> Result<EncString, CryptoError>
Source§impl OptionFromWasmAbi for SymmetricCryptoKey
Available on crate feature wasm only.
impl OptionFromWasmAbi for SymmetricCryptoKey
wasm only.Source§impl PartialEq for SymmetricCryptoKey
impl PartialEq for SymmetricCryptoKey
Source§impl Serialize for SymmetricCryptoKey
impl Serialize for SymmetricCryptoKey
Source§impl TryFrom<&Bytes<BitwardenLegacyKeyContentFormat>> for SymmetricCryptoKey
impl TryFrom<&Bytes<BitwardenLegacyKeyContentFormat>> for SymmetricCryptoKey
Source§type Error = CryptoError
type Error = CryptoError
Source§impl TryFrom<&CoseKey> for SymmetricCryptoKey
impl TryFrom<&CoseKey> for SymmetricCryptoKey
Source§impl TryFrom<&SymmetricCryptoKey> for MasterKey
impl TryFrom<&SymmetricCryptoKey> for MasterKey
Source§type Error = CryptoError
type Error = CryptoError
Source§fn try_from(value: &SymmetricCryptoKey) -> Result<Self, CryptoError>
fn try_from(value: &SymmetricCryptoKey) -> Result<Self, CryptoError>
Source§impl TryFrom<B64> for SymmetricCryptoKey
impl TryFrom<B64> for SymmetricCryptoKey
Source§impl TryFrom<EncodedSymmetricKey> for SymmetricCryptoKey
impl TryFrom<EncodedSymmetricKey> for SymmetricCryptoKey
Source§type Error = CryptoError
type Error = CryptoError
Source§impl TryFrom<JsValue> for SymmetricCryptoKey
Available on crate feature wasm only.
impl TryFrom<JsValue> for SymmetricCryptoKey
wasm only.Source§impl TryFrom<String> for SymmetricCryptoKey
impl TryFrom<String> for SymmetricCryptoKey
Source§impl WasmDescribe for SymmetricCryptoKey
Available on crate feature wasm only.
impl WasmDescribe for SymmetricCryptoKey
wasm only.impl CryptoKey for SymmetricCryptoKey
Auto Trait Implementations§
impl Freeze for SymmetricCryptoKey
impl RefUnwindSafe for SymmetricCryptoKey
impl Send for SymmetricCryptoKey
impl Sync for SymmetricCryptoKey
impl Unpin for SymmetricCryptoKey
impl UnsafeUnpin for SymmetricCryptoKey
impl UnwindSafe for SymmetricCryptoKey
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.