Struct bc_components::SymmetricKey
source · pub struct SymmetricKey(/* private fields */);Expand description
A symmetric encryption key.
Implementations§
source§impl SymmetricKey
impl SymmetricKey
pub const SYMMETRIC_KEY_SIZE: usize = 32usize
sourcepub fn new_using(rng: &mut impl RandomNumberGenerator) -> Self
pub fn new_using(rng: &mut impl RandomNumberGenerator) -> Self
Create a new random symmetric key using the given random number generator.
sourcepub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
pub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
Create a new symmetric key from data.
sourcepub fn from_hex(hex: impl AsRef<str>) -> Result<Self>
pub fn from_hex(hex: impl AsRef<str>) -> Result<Self>
Create a new symmetric key from the given hexadecimal string.
Panics
Panics if the string is not exactly 24 hexadecimal digits.
sourcepub fn encrypt(
&self,
plaintext: impl Into<Bytes>,
aad: Option<impl Into<Bytes>>,
nonce: Option<impl AsRef<Nonce>>
) -> EncryptedMessage
pub fn encrypt( &self, plaintext: impl Into<Bytes>, aad: Option<impl Into<Bytes>>, nonce: Option<impl AsRef<Nonce>> ) -> EncryptedMessage
Encrypt the given plaintext with this key, and the given additional authenticated data and nonce.
sourcepub fn encrypt_with_digest(
&self,
plaintext: impl Into<Bytes>,
digest: impl AsRef<Digest>,
nonce: Option<impl AsRef<Nonce>>
) -> EncryptedMessage
pub fn encrypt_with_digest( &self, plaintext: impl Into<Bytes>, digest: impl AsRef<Digest>, nonce: Option<impl AsRef<Nonce>> ) -> EncryptedMessage
Encrypt the given plaintext with this key, and the given digest of the plaintext, and nonce.
Trait Implementations§
source§impl AsRef<SymmetricKey> for SymmetricKey
impl AsRef<SymmetricKey> for SymmetricKey
source§fn as_ref(&self) -> &SymmetricKey
fn as_ref(&self) -> &SymmetricKey
Converts this type into a shared reference of the (usually inferred) input type.
source§impl CBORDecodable for SymmetricKey
impl CBORDecodable for SymmetricKey
source§impl CBOREncodable for SymmetricKey
impl CBOREncodable for SymmetricKey
source§impl CBORTagged for SymmetricKey
impl CBORTagged for SymmetricKey
source§impl CBORTaggedDecodable for SymmetricKey
impl CBORTaggedDecodable for SymmetricKey
source§fn from_untagged_cbor(cbor: &CBOR) -> Result<Self>
fn from_untagged_cbor(cbor: &CBOR) -> Result<Self>
Creates an instance of this type by decoding it from untagged CBOR.
source§fn from_tagged_cbor(cbor: &CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: &CBOR) -> Result<Self, Error>where
Self: Sized,
Creates an instance of this type by decoding it from tagged CBOR.
source§impl CBORTaggedEncodable for SymmetricKey
impl CBORTaggedEncodable for SymmetricKey
source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Returns the untagged CBOR encoding of this instance.
source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Returns the tagged CBOR encoding of this instance.
source§impl Clone for SymmetricKey
impl Clone for SymmetricKey
source§fn clone(&self) -> SymmetricKey
fn clone(&self) -> SymmetricKey
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for SymmetricKey
impl Debug for SymmetricKey
source§impl Default for SymmetricKey
impl Default for SymmetricKey
source§impl<'a> From<&'a SymmetricKey> for &'a [u8; 32]
impl<'a> From<&'a SymmetricKey> for &'a [u8; 32]
source§fn from(digest: &'a SymmetricKey) -> Self
fn from(digest: &'a SymmetricKey) -> Self
Converts to this type from the input type.
source§impl From<&SymmetricKey> for SymmetricKey
impl From<&SymmetricKey> for SymmetricKey
source§fn from(digest: &SymmetricKey) -> Self
fn from(digest: &SymmetricKey) -> Self
Converts to this type from the input type.
source§impl From<&SymmetricKey> for Vec<u8>
impl From<&SymmetricKey> for Vec<u8>
source§fn from(digest: &SymmetricKey) -> Self
fn from(digest: &SymmetricKey) -> Self
Converts to this type from the input type.
source§impl From<SymmetricKey> for CBOR
impl From<SymmetricKey> for CBOR
source§fn from(value: SymmetricKey) -> Self
fn from(value: SymmetricKey) -> Self
Converts to this type from the input type.
source§impl From<SymmetricKey> for Vec<u8>
impl From<SymmetricKey> for Vec<u8>
source§fn from(digest: SymmetricKey) -> Self
fn from(digest: SymmetricKey) -> Self
Converts to this type from the input type.
source§impl Hash for SymmetricKey
impl Hash for SymmetricKey
source§impl PartialEq for SymmetricKey
impl PartialEq for SymmetricKey
source§fn eq(&self, other: &SymmetricKey) -> bool
fn eq(&self, other: &SymmetricKey) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl TryFrom<&CBOR> for SymmetricKey
impl TryFrom<&CBOR> for SymmetricKey
source§impl TryFrom<CBOR> for SymmetricKey
impl TryFrom<CBOR> for SymmetricKey
source§impl URDecodable for SymmetricKey
impl URDecodable for SymmetricKey
source§impl UREncodable for SymmetricKey
impl UREncodable for SymmetricKey
impl Eq for SymmetricKey
impl StructuralEq for SymmetricKey
impl StructuralPartialEq for SymmetricKey
impl URCodable for SymmetricKey
Auto Trait Implementations§
impl RefUnwindSafe for SymmetricKey
impl Send for SymmetricKey
impl Sync for SymmetricKey
impl Unpin for SymmetricKey
impl UnwindSafe for SymmetricKey
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
Mutably borrows from an owned value. Read more