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>where
T: SecureSanitize,
P: SecretStoragePolicy<T>,
impl<T, P> AllowlistedSecret<T, P>where
T: SecureSanitize,
P: SecretStoragePolicy<T>,
Sourcepub const fn policy_rationale() -> &'static str
pub const fn policy_rationale() -> &'static str
Return the policy’s review rationale for this exact storage type.
Sourcepub fn into_cleared(self)
pub fn into_cleared(self)
Consume the wrapper after first clearing the wrapped value.
Source§impl<T, P> AllowlistedSecret<T, P>where
T: StableSharedSecretStorage,
P: SecretStoragePolicy<T>,
impl<T, P> AllowlistedSecret<T, P>where
T: StableSharedSecretStorage,
P: SecretStoragePolicy<T>,
Sourcepub fn with_secret<R>(&self, inspect: impl FnOnce(&T) -> R) -> R
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>where
T: StableMutableSecretStorage,
P: SecretStoragePolicy<T>,
impl<T, P> AllowlistedSecret<T, P>where
T: StableMutableSecretStorage,
P: SecretStoragePolicy<T>,
Sourcepub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut T) -> R) -> R
pub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut T) -> R) -> R
Run a closure with policy-approved mutable-stable storage.