pub struct MappingStore { /* private fields */ }Expand description
Thread-safe concurrent one-way replacement store.
Caches forward mappings for per-run consistency (same input always produces the same output within a run). There is no reverse map, no journal, and no persistence — replacements are one-way only.
See the module-level documentation for concurrency and memory details.
Implementations§
Source§impl MappingStore
impl MappingStore
Sourcepub fn new(
generator: Arc<dyn ReplacementGenerator>,
capacity_limit: Option<usize>,
) -> Self
pub fn new( generator: Arc<dyn ReplacementGenerator>, capacity_limit: Option<usize>, ) -> Self
Create a new, empty mapping store.
§Arguments
generator— replacement strategy (HMAC or random).capacity_limit— optional max number of unique mappings.
Sourcepub fn new_with_allowlist(
generator: Arc<dyn ReplacementGenerator>,
capacity_limit: Option<usize>,
allowlist: Arc<AllowlistMatcher>,
) -> Self
pub fn new_with_allowlist( generator: Arc<dyn ReplacementGenerator>, capacity_limit: Option<usize>, allowlist: Arc<AllowlistMatcher>, ) -> Self
Create a new store with an allowlist. Values matching the allowlist are returned unchanged and never recorded in the forward map.
Sourcepub fn allowlist(&self) -> Option<&AllowlistMatcher>
pub fn allowlist(&self) -> Option<&AllowlistMatcher>
Return the allowlist attached to this store, if any.
Sourcepub fn get_or_insert(
&self,
category: &Category,
original: &str,
) -> Result<CompactString>
pub fn get_or_insert( &self, category: &Category, original: &str, ) -> Result<CompactString>
Get or create the sanitized replacement for (category, original).
This is the primary API for one-way sanitization.
Hot-path allocation: When the value is already cached, this method
is allocation-free. The inner DashMap::get accepts &str directly via
ZeroizingString: Borrow<str>, so no temporary String is constructed.
Thread-safety: Uses DashMap::entry() which holds a shard-level
lock only for the duration of the insert closure. The generator is
called inside the lock, but generation is fast (one HMAC or one RNG
call). Capacity enforcement uses compare_exchange to prevent
TOCTOU over-insertion.
Per-run consistency: Once a value is mapped, all subsequent lookups return the same sanitized value (first-writer-wins).
§Errors
Returns SanitizeError::CapacityExceeded if the store has
reached its configured capacity limit.
Sourcepub fn forward_lookup(
&self,
category: &Category,
original: &str,
) -> Option<CompactString>
pub fn forward_lookup( &self, category: &Category, original: &str, ) -> Option<CompactString>
Look up an existing forward mapping without creating one.
Sourcepub fn register_alias(&self, category: &Category, alias: &str, sanitized: &str)
pub fn register_alias(&self, category: &Category, alias: &str, sanitized: &str)
Register alias as an additional original that maps to the same
sanitized replacement under category.
Structured processors use this to record the source-escaped form of a
discovered value — e.g. the JSON value a"b appears in the raw bytes as
a\"b. The format-preserving scanner matches against raw input bytes, so
without the alias the escaped occurrence would not be redacted. Aliasing
(rather than a fresh mapping) keeps the escaped occurrence consistent with
the parsed value’s token.
First-writer-wins: an existing mapping for alias is left unchanged.
Allowlisted or empty aliases are ignored. Like Self::get_or_insert,
the new entry participates in Self::iter_since.
Sourcepub fn clear(&self)
pub fn clear(&self)
Remove all mappings, zeroizing the original plaintexts.
Takes &self so it is usable on a shared Arc<MappingStore>. Only
call this after all concurrent readers and writers have finished —
DashMap::clear acquires shard locks one at a time, so a concurrent
get_or_insert racing with clear will observe a partially-cleared
store.
Breaking change in 0.13.0: the signature changed from
clear(&mut self) to clear(&self).
Sourcepub fn snapshot(&self) -> StoreSnapshot
pub fn snapshot(&self) -> StoreSnapshot
Snapshot the current insertion count.
Returns a StoreSnapshot that can be passed to Self::iter_since to
iterate only the entries added after this point — useful for
finding which mappings a structured processor pass discovered without
building a full HashSet of all existing keys.
O(1), no allocation.
Breaking change in 0.13.0: previously returned usize;
now returns StoreSnapshot.
Sourcepub fn iter_since(
&self,
since: StoreSnapshot,
) -> impl Iterator<Item = (Category, CompactString, CompactString)> + '_
pub fn iter_since( &self, since: StoreSnapshot, ) -> impl Iterator<Item = (Category, CompactString, CompactString)> + '_
Iterate over entries added at or after the given snapshot.
since is the value returned by a previous call to Self::snapshot.
Entries whose insertion index is ≥ since are yielded; older entries
are skipped. Still O(n) in total store size, but avoids allocating a
HashSet of all prior keys. Use StoreSnapshot::start to iterate
all entries.
Breaking change in 0.13.0: the parameter type changed from usize
to StoreSnapshot.
Implementation note: the inner .collect::<Vec<_>>() inside the
flat_map is required to release the DashMap shard lock before
yielding items — it allocates one Vec per category shard visited.
Sourcepub fn iter(
&self,
) -> impl Iterator<Item = (Category, CompactString, CompactString)> + '_
pub fn iter( &self, ) -> impl Iterator<Item = (Category, CompactString, CompactString)> + '_
Iterate over all mappings. Yields (category, original, sanitized).
Note: iteration over DashMap is not snapshot-consistent if concurrent
inserts are happening. Call this after all workers have finished.
Implementation note: allocates one Vec per category shard to release
the DashMap shard lock between categories.
Trait Implementations§
Source§impl Drop for MappingStore
Zeroize original keys stored in the forward map on drop.
impl Drop for MappingStore
Zeroize original keys stored in the forward map on drop.
Auto Trait Implementations§
impl !Freeze for MappingStore
impl !RefUnwindSafe for MappingStore
impl !UnwindSafe for MappingStore
impl Send for MappingStore
impl Sync for MappingStore
impl Unpin for MappingStore
impl UnsafeUnpin for MappingStore
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
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.