pub struct SecretRedactor { /* private fields */ }Expand description
Pattern-based redactor. Matches credential-shaped substrings in
rendered text and replaces them with [REDACTED:<pattern>]
markers. Deliberately a small hand-rolled scanner instead of
pulling in regex for this one site — the patterns are simple
(prefix-anchored, alnum body) and avoiding the regex compile lets
the redactor run in test paths without registering a global
LazyLock.
§Patterns
| Name | Shape |
|---|---|
api_key | `(sk |
jwt | eyJ + alnum + . + alnum + . + alnum |
bearer | Bearer + ≥ 20 alnum/_-. chars |
conn_string_credential | ://user:password@ segment of a URI |
The byte length of every match is recorded in
RedactionReport::bytes_redacted so an auditor can tell
“redactor fired and removed 1.2 KiB” without seeing the secret.
Implementations§
Source§impl SecretRedactor
impl SecretRedactor
Sourcepub fn redact(&self, input: &str) -> (String, RedactionReport)
pub fn redact(&self, input: &str) -> (String, RedactionReport)
Scan input and return (redacted_text, report). Patterns
are applied in a fixed order so the report is deterministic.
Sourcepub fn scan(&self, input: &str) -> RedactionReport
pub fn scan(&self, input: &str) -> RedactionReport
Scan input and return only the report — useful for the
“is this slot allowed to carry a credential?” check before
committing to a redaction in an operator-controlled slot.
Trait Implementations§
Source§impl Debug for SecretRedactor
impl Debug for SecretRedactor
Source§impl Default for SecretRedactor
impl Default for SecretRedactor
Source§fn default() -> SecretRedactor
fn default() -> SecretRedactor
Auto Trait Implementations§
impl Freeze for SecretRedactor
impl RefUnwindSafe for SecretRedactor
impl Send for SecretRedactor
impl Sync for SecretRedactor
impl Unpin for SecretRedactor
impl UnsafeUnpin for SecretRedactor
impl UnwindSafe for SecretRedactor
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> 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request