Skip to main content

Vault

Struct Vault 

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

Maps a redaction sentinel to the original plaintext it stands in for, and allocates a stable per-type counter so two distinct values of the same type stay distinct ([REDACTED_EMAIL_1_<suffix>] vs [REDACTED_EMAIL_2_<suffix>]).

Implementations§

Source§

impl Vault

Source

pub fn new() -> Self

Build a vault with a freshly-minted per-request random nonce, derived from the thread RNG so two concurrent requests never share a sentinel namespace.

Source

pub fn deterministic(key: &[u8]) -> Self

Build a deterministic vault keyed by caller-owned secret key: every sentinel suffix is HMAC(key, value)[:n], so the same value under the same key redacts byte-identically across independent vaults. The key is copied into the vault and zeroized on drop.

Source

pub fn with_strategy(strategy: NonceStrategy) -> Self

Build a vault under an explicit NonceStrategy — the general entry point behind Self::new (Random) and Self::deterministic.

Source

pub fn with_nonce(nonce: String) -> Self

Build a vault with an explicit nonce. Test-only escape hatch so a test can assert against a fixed sentinel; production always mints a random one via Self::new.

Source

pub fn nonce(&self) -> Option<&str>

The request’s random nonce, or None in deterministic mode (where the suffix is per-value, not per-request). For audit and tests only.

Source

pub fn is_empty(&self) -> bool

Whether the vault holds any redaction. An empty vault is the byte-identical-passthrough signal on the response path.

Source

pub fn len(&self) -> usize

Number of distinct values interned.

Source

pub fn intern(&mut self, ty: &str, original: &str, restorable: bool) -> String

Intern original under entity type ty, returning its sentinel. The same original value seen twice in one request returns the same sentinel; a new value allocates the next per-type counter.

restorable marks the sentinel for the restore pass: true for a RoundTrip input redaction (the caller’s own PII, echoed back), false for a OneWay redaction (a secret, or model-emitted PII masked on output). Restorability is sticky-true: if a value is interned restorable once, a later OneWay intern of the same value (the model echoing the caller’s literal input) keeps it restorable, because it is still the caller’s value.

Source

pub fn is_restorable(&self, placeholder: &str) -> bool

Whether placeholder was interned as restorable (a RoundTrip input redaction). The restore pass consults this so it never rehydrates a OneWay sentinel — a secret, or model-emitted PII masked on output — even when that sentinel shares an entity type with a restored input value.

Source

pub fn original_for(&self, placeholder: &str) -> Option<&str>

Look up the original for a sentinel (exact match). The detokenize half of the round-trip; the proptest pins intern then original_for as an identity.

Source

pub fn entries(&self) -> impl Iterator<Item = (&str, &str)>

Iterate (sentinel, original) pairs for the restore pass.

Source

pub fn interned_counts(&self) -> impl Iterator<Item = (&str, u32)>

Iterate (entity_type, count) for every type interned so far, where the count is the number of distinct values redacted under that type. The keys are entity type labels (EMAIL, AWS_ACCESS_KEY…), never values — so a metrics consumer can diff this snapshot across a scanner run to attribute redactions per type without ever touching plaintext.

Source

pub fn note_restored(&mut self, ty: &str, n: u32)

Record that n sentinels of entity type ty were restored against this vault. The restore pass calls this so a metrics consumer can read the restored tally; it stores counts and the type label only.

Source

pub fn restored_counts(&self) -> impl Iterator<Item = (&str, u32)>

Iterate (entity_type, count) of restores recorded via Vault::note_restored. Type labels and counts only.

Trait Implementations§

Source§

impl Debug for Vault

Source§

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

Reports only counts and mode — never the originals, nonce, or key, which are the host-side secret this type exists to hold.

Source§

impl Default for Vault

Source§

fn default() -> Self

Mints a fresh random nonce, same as Self::new — there is no suffix-less vault, so default() is never a footgun.

Source§

impl Drop for Vault

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

Auto Trait Implementations§

§

impl Freeze for Vault

§

impl RefUnwindSafe for Vault

§

impl Send for Vault

§

impl Sync for Vault

§

impl Unpin for Vault

§

impl UnsafeUnpin for Vault

§

impl UnwindSafe for Vault

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V