pub struct SecretSentinel { /* private fields */ }Expand description
The main entry point for secret detection and redaction.
- WHAT – Holds a collection of
RedactionRules. - HOW – Provides methods to scrub a string (
scrub_text) and to simply check whether any secret is present (contains_secrets). - WHY – Centralising the rules in a struct enables reuse and makes testing straightforward.
Implementations§
Source§impl SecretSentinel
impl SecretSentinel
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Constructs a SecretSentinel pre‑populated with a sensible default set of rules.
- WHAT – Returns a sentinel containing three rules: OpenAI, AWS and a generic secret matcher.
- HOW – Instantiates
RedactionRules using the lazily‑initialised regexes above and stores them in therulesvector. - WHY – Provides a ready‑to‑use configuration for typical development environments while still allowing callers to create custom instances.
Sourcepub fn scrub_text(&self, input: &str) -> String
pub fn scrub_text(&self, input: &str) -> String
Redacts all secrets found in input according to the configured rules.
- WHAT – Returns a new
Stringwhere each match has been replaced. - HOW – Iterates over the rules and applies
replace_allfor each. - WHY – Performing the replacements sequentially ensures that overlapping patterns are handled deterministically.
Sourcepub fn contains_secrets(&self, input: &str) -> bool
pub fn contains_secrets(&self, input: &str) -> bool
Checks whether any of the configured rules match input.
- WHAT – Returns
trueif at least one rule’s pattern matches. - HOW – Uses
Iter::anyoverself.ruleswithis_match. - WHY – A quick predicate useful for short‑circuiting logging or error handling before performing the full redaction.
Auto Trait Implementations§
impl Freeze for SecretSentinel
impl RefUnwindSafe for SecretSentinel
impl Send for SecretSentinel
impl Sync for SecretSentinel
impl Unpin for SecretSentinel
impl UnwindSafe for SecretSentinel
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
Mutably borrows from an owned value. Read more