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

Implementation for CryptorKey

source

const CRYPTOR_KEY_LENGTH: usize = 32usize

Length of the encryption key in bytes

source

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 the CryptoRng and RngCore 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).

source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self, CryptoError>

Returns the CryptorKey stored in a file.

source

pub fn from_bytes(cryptor_key: &[u8]) -> Result<Self, CryptoError>

Returns the CryptorKey key based on key material in the caller’s byte array.

source

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

source§

fn clone(&self) -> CryptorKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CryptorKey

An implementation of the std::fmt::Debug trait for CryptorKey

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for CryptorKey

An implementation of the std::fmt::Display trait for CryptorKey

source§

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

Formats the value using the given formatter. Read more
source§

impl Drop for CryptorKey

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl PartialEq for CryptorKey

Implement the PartialEq trait for the CryptorKey type.

source§

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 other CryptorKey instance to compare with.
§Returns

Returns true if the data and context fields are equal between the two CryptorKey instances, Otherwise returns false.

1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Zeroize for CryptorKey

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
source§

impl Eq for CryptorKey

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
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
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

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

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

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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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