Key

Enum Key 

Source
pub enum Key {
    Aes256([u8; 32]),
    Aes192([u8; 24]),
    Aes128([u8; 16]),
}
Expand description

Represents different AES key sizes.

AES (Advanced Encryption Standard) supports three key sizes:

  • 128-bit (16 bytes)
  • 192-bit (24 bytes)
  • 256-bit (32 bytes)

This enum allows for type-safe handling of these different key sizes.

Variants§

§

Aes256([u8; 32])

256-bit AES key (32 bytes)

§

Aes192([u8; 24])

192-bit AES key (24 bytes)

§

Aes128([u8; 16])

128-bit AES key (16 bytes)

Implementations§

Source§

impl Key

Source

pub const fn capacity(&self) -> usize

Returns the capacity (size in bytes) of the key.

§Returns
  • 32 for Aes256
  • 24 for Aes192
  • 16 for Aes128
Source

pub const fn as_slice(&self) -> &[u8]

Returns a reference to the key as a byte slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable reference to the key as a byte slice.

Source

pub fn zero(&mut self)

Zeros out the key for security purposes.

This method uses the zeroize crate to ensure that the key material is securely erased from memory.

This is called in the Key drop implementation.

Trait Implementations§

Source§

impl Drop for Key

Source§

fn drop(&mut self)

Zeroes the underlying key material.

Source§

impl From<[u8; 16]> for Key

Source§

fn from(value: [u8; 16]) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 24]> for Key

Source§

fn from(value: [u8; 24]) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 32]> for Key

Source§

fn from(value: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl Zeroize for Key

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.

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnwindSafe for Key

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.