Skip to main content

SecretKey

Struct SecretKey 

Source
pub struct SecretKey { /* private fields */ }
Expand description

Plaintext cryptographic key material owned by paysec-keyblock.

SecretKey provides basic in-process protection for plaintext key material:

  • its contents are redacted from Debug output,
  • its owned byte buffer is zeroized when dropped,
  • raw key bytes are available only through an explicit SecretKey::expose_secret call.

This type is intended for plaintext key material handled by the TR-31 domain layer. It is not used for provider-managed keys such as KBPK, KBEK, or KBAK, which may be represented by opaque HSM handles or other provider-specific types.

§Security

SecretKey provides memory-hygiene and accidental-disclosure protection. It does not guarantee that key material has never existed elsewhere in process memory. For example, callers may retain their own copies, and operating-system facilities such as swap, crash dumps, or process memory inspection are outside the scope of this type.

Implementations§

Source§

impl SecretKey

Source

pub fn new(bytes: Vec<u8>) -> Self

Create a secret key by taking ownership of an existing byte vector.

Taking ownership avoids making an additional copy of the key material.

Source

pub fn from_slice(bytes: &[u8]) -> Self

Create a secret key by copying key material from a byte slice.

The caller remains responsible for any original copy represented by bytes.

Source

pub fn expose_secret(&self) -> &[u8]

Explicitly expose the plaintext key bytes.

This operation is intentionally named to make access to plaintext key material visible during code review.

Source

pub fn len(&self) -> usize

Return the key length in bytes without exposing the key material.

Source

pub fn is_empty(&self) -> bool

Return whether the key contains no bytes.

Trait Implementations§

Source§

impl Debug for SecretKey

Source§

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

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

impl From<Vec<u8>> for SecretKey

Source§

fn from(bytes: Vec<u8>) -> Self

Converts to this type from the input type.

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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.