Skip to main content

AllowlistedSecret

Struct AllowlistedSecret 

Source
pub struct AllowlistedSecret<T: SecureSanitize, P> { /* private fields */ }
Expand description

Clear-on-drop secret gated by an application-controlled storage allow-list.

Unlike Secret<T>, construction and exposure require a policy type that implements SecretStoragePolicy<T> for the exact wrapped type. This lets a high-assurance application centralize accepted storage types and prevents a dependency’s unrelated storage-marker implementation from automatically entering that accepted set.

The policy is defense in depth. Shared and mutable access still require StableSharedSecretStorage and StableMutableSecretStorage respectively. An incorrect policy or storage-contract implementation can invalidate the clearing guarantee, but cannot be relied on for Rust memory safety.

There is intentionally no field-only derive for storage stability. A proc macro cannot inspect later inherent methods, trait implementations, interior mutation, returned guards, callbacks, or deferred cleanup.

An unapproved type cannot be constructed under a policy:

use sanitization::{
    define_secret_storage_policy, AllowlistedSecret, SecretBytes,
};

define_secret_storage_policy! {
    DeploymentStoragePolicy {
        SecretBytes<32> => "reviewed fixed key storage",
    }
}

let _ = AllowlistedSecret::<SecretBytes<16>, DeploymentStoragePolicy>::new(
    SecretBytes::from_array([0; 16]),
);

Implementations§

Source§

impl<T, P> AllowlistedSecret<T, P>

Source

pub const fn new(inner: T) -> Self

Wrap a value approved by P.

Source

pub const fn policy_rationale() -> &'static str

Return the policy’s review rationale for this exact storage type.

Source

pub fn into_cleared(self)

Consume the wrapper after first clearing the wrapped value.

Source§

impl<T, P> AllowlistedSecret<T, P>

Source

pub fn with_secret<R>(&self, inspect: impl FnOnce(&T) -> R) -> R

Run a closure with policy-approved shared-stable storage.

Source§

impl<T, P> AllowlistedSecret<T, P>

Source

pub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut T) -> R) -> R

Run a closure with policy-approved mutable-stable storage.

Trait Implementations§

Source§

impl<T: SecureSanitize, P> Debug for AllowlistedSecret<T, P>

Source§

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

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

impl<T, P> Default for AllowlistedSecret<T, P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: SecureSanitize, P> Drop for AllowlistedSecret<T, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: SecureSanitize, P> SecureSanitize for AllowlistedSecret<T, P>

Source§

fn secure_sanitize(&mut self)

Clear the sensitive bytes owned by this value.
Source§

impl<T, P> StableMutableSecretStorage for AllowlistedSecret<T, P>

Source§

impl<T, P> StableSharedSecretStorage for AllowlistedSecret<T, P>

Auto Trait Implementations§

§

impl<T, P> Freeze for AllowlistedSecret<T, P>
where T: Freeze,

§

impl<T, P> RefUnwindSafe for AllowlistedSecret<T, P>
where T: RefUnwindSafe,

§

impl<T, P> Send for AllowlistedSecret<T, P>
where T: Send,

§

impl<T, P> Sync for AllowlistedSecret<T, P>
where T: Sync,

§

impl<T, P> Unpin for AllowlistedSecret<T, P>
where T: Unpin,

§

impl<T, P> UnsafeUnpin for AllowlistedSecret<T, P>
where T: UnsafeUnpin,

§

impl<T, P> UnwindSafe for AllowlistedSecret<T, P>
where T: UnwindSafe,

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.