pub enum SymmetricCryptoKey {
Aes256CbcKey(Aes256CbcKey),
Aes256CbcHmacKey(Aes256CbcHmacKey),
XChaCha20Poly1305Key(XChaCha20Poly1305Key),
}
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
Implementations§
Source§impl SymmetricCryptoKey
impl SymmetricCryptoKey
const AES256_CBC_KEY_LEN: usize = 32usize
const AES256_CBC_HMAC_KEY_LEN: usize = 64usize
Sourcepub(crate) fn make_aes256_cbc_hmac_key_internal(
rng: impl RngCore + CryptoRng,
) -> Self
pub(crate) fn make_aes256_cbc_hmac_key_internal( rng: impl RngCore + 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_aes256_cbc_hmac_key() -> Self
pub fn make_aes256_cbc_hmac_key() -> Self
Generate a new random AES256_CBC_HMAC SymmetricCryptoKey
Sourcepub fn make_xchacha20_poly1305_key() -> Self
pub fn make_xchacha20_poly1305_key() -> Self
Generate a new random XChaCha20Poly1305 SymmetricCryptoKey
Sourcepub fn to_encoded(&self) -> Vec<u8> ⓘ
pub fn to_encoded(&self) -> Vec<u8> ⓘ
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. SymmetricCryptoKey::XChaCha20Poly1305Key is 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) -> Vec<u8> ⓘ
pub(crate) fn to_encoded_raw(&self) -> Vec<u8> ⓘ
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. SymmetricCryptoKey::XChaCha20Poly1305Key is encoded as a COSE key, serialized to a byte array. The COSE key can be either directly encrypted using COSE, where the content format hints an the key type, or can be represented as a byte array, if padded to be larger than the byte array representation of the other key types using the aforementioned SymmetricCryptoKey::to_encoded function.
pub fn to_base64(&self) -> String
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 Debug for SymmetricCryptoKey
impl Debug for SymmetricCryptoKey
Source§impl Drop for SymmetricCryptoKey
impl Drop for SymmetricCryptoKey
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<SymmetricCryptoKey, EncString> for &[u8]
impl KeyEncryptable<SymmetricCryptoKey, EncString> for &[u8]
fn encrypt_with_key( self, key: &SymmetricCryptoKey, ) -> Result<EncString, CryptoError>
Source§impl KeyEncryptable<SymmetricCryptoKey, EncString> for &str
impl KeyEncryptable<SymmetricCryptoKey, EncString> for &str
fn encrypt_with_key( self, key: &SymmetricCryptoKey, ) -> Result<EncString, CryptoError>
Source§impl KeyEncryptable<SymmetricCryptoKey, EncString> for String
impl KeyEncryptable<SymmetricCryptoKey, EncString> for String
fn encrypt_with_key( self, key: &SymmetricCryptoKey, ) -> Result<EncString, CryptoError>
Source§impl PartialEq for SymmetricCryptoKey
impl PartialEq for SymmetricCryptoKey
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<&mut [u8]> for SymmetricCryptoKey
impl TryFrom<&mut [u8]> for SymmetricCryptoKey
Source§fn try_from(value: &mut [u8]) -> Result<Self, Self::Error>
fn try_from(value: &mut [u8]) -> Result<Self, Self::Error>
Note: This function takes the byte slice by mutable reference and will zero out all the data in it. This is to prevent the key from being left in memory.
Source§type Error = CryptoError
type Error = CryptoError
Source§impl TryFrom<String> for SymmetricCryptoKey
impl TryFrom<String> for SymmetricCryptoKey
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 UnwindSafe for SymmetricCryptoKey
Blanket Implementations§
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 moreSource§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