Struct lock_keeper::crypto::cryptor_key::CryptorKey
source · pub struct CryptorKey {
pub(super) key_material: Box<Key>,
config: SensitiveInfoConfig,
}
Expand description
The CryptorKey
type is a default-length symmetric encryption key
for an AEAD scheme. It can be used to securely encrypt data.
Fields§
§key_material: Box<Key>
§config: SensitiveInfoConfig
Implementations§
source§impl CryptorKey
impl CryptorKey
Implementation for CryptorKey
sourceconst CRYPTOR_KEY_LENGTH: usize = 32usize
const CRYPTOR_KEY_LENGTH: usize = 32usize
Length of the encryption key in bytes
sourcepub fn new(rng: &mut (impl CryptoRng + RngCore)) -> Self
pub fn new(rng: &mut (impl CryptoRng + RngCore)) -> Self
Constructs a new instance of the CryptorKey
type.
§Arguments
rng
- A mutable reference to an object implementing both theCryptoRng
andRngCore
traits. This is used to generate the cryptographic key for the ChaCha20Poly1305 algorithm.
§Returns
Returns a new instance of the CryptorKey
type with a fresh
cryptographic key generated via the provided random number generator
(rng
) and a new SensitiveInfoConfig
object.
A CryptorKey
is generated uniformly at random. It is a 32-byte pseudorandom key for use in the ChaCha20Poly1305 scheme for
authenticated encryption with associated data (AEAD).
sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, CryptoError>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, CryptoError>
Returns the CryptorKey
stored in a file.
sourcepub fn from_bytes(cryptor_key: &[u8]) -> Result<Self, CryptoError>
pub fn from_bytes(cryptor_key: &[u8]) -> Result<Self, CryptoError>
Returns the CryptorKey
key based on key material in the caller’s
byte array.
sourcepub fn into_bytes(self) -> [u8; 32]
pub fn into_bytes(self) -> [u8; 32]
Converts CryptorKey
to a byte array.
§Warning
This method gives direct access to the key material bytes.
The caller should be careful to manually zeroize them after use to
prevent unintended exposure of sensitive information. Consider using
the zeroize
crate to securely zero the data.
§Example
use zeroize::Zeroize;
use lock_keeper::crypto::CryptorKey;///
let mut rng = rand::thread_rng();
let encryption_key = CryptorKey::new(&mut rng);
let mut key_bytes = encryption_key.into_bytes();
// Use the key bytes...
// When done, zeroize the key bytes
key_bytes.zeroize();
Trait Implementations§
source§impl Clone for CryptorKey
impl Clone for CryptorKey
source§fn clone(&self) -> CryptorKey
fn clone(&self) -> CryptorKey
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CryptorKey
impl Debug for CryptorKey
An implementation of the std::fmt::Debug
trait for CryptorKey
source§impl Display for CryptorKey
impl Display for CryptorKey
An implementation of the std::fmt::Display
trait for CryptorKey
source§impl Drop for CryptorKey
impl Drop for CryptorKey
source§impl PartialEq for CryptorKey
impl PartialEq for CryptorKey
Implement the PartialEq
trait for the CryptorKey
type.
source§fn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Determines if two CryptorKey
instances are equal.
This function compares the key_material
fields of two CryptorKey
instances. It does not compare the config
fields because the
config
field does not affect the functional equivalence of two
CryptorKey
instances.
§Arguments
other
- The otherCryptorKey
instance to compare with.
§Returns
Returns true
if the data
and context
fields are equal between the
two CryptorKey
instances, Otherwise returns false
.
source§impl Zeroize for CryptorKey
impl Zeroize for CryptorKey
impl Eq for CryptorKey
Auto Trait Implementations§
impl Freeze for CryptorKey
impl RefUnwindSafe for CryptorKey
impl Send for CryptorKey
impl Sync for CryptorKey
impl Unpin for CryptorKey
impl UnwindSafe for CryptorKey
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request