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
impl Vault
Sourcepub fn new() -> Self
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.
Sourcepub fn deterministic(key: &[u8]) -> Self
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.
Sourcepub fn with_strategy(strategy: NonceStrategy) -> Self
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.
Sourcepub fn with_nonce(nonce: String) -> Self
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.
Sourcepub fn nonce(&self) -> Option<&str>
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.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn intern(&mut self, ty: &str, original: &str, restorable: bool) -> String
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.
Sourcepub fn is_restorable(&self, placeholder: &str) -> bool
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.
Sourcepub fn original_for(&self, placeholder: &str) -> Option<&str>
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.
Sourcepub fn entries(&self) -> impl Iterator<Item = (&str, &str)>
pub fn entries(&self) -> impl Iterator<Item = (&str, &str)>
Iterate (sentinel, original) pairs for the restore pass.
Sourcepub fn interned_counts(&self) -> impl Iterator<Item = (&str, u32)>
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.
Sourcepub fn note_restored(&mut self, ty: &str, n: u32)
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.
Sourcepub fn restored_counts(&self) -> impl Iterator<Item = (&str, u32)>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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