pub struct Detectors { /* private fields */ }Expand description
A compiled detector set. Construct once per process from the loaded
config (Detectors::new) and share via Arc; detection itself is
&self and thread-safe.
Implementations§
Source§impl Detectors
impl Detectors
Sourcepub fn new(cfg: &RedactionConfig) -> Result<Self>
pub fn new(cfg: &RedactionConfig) -> Result<Self>
Compile the built-in detectors plus the user rules from cfg.
§Errors
An invalid user pattern is an actionable ConfigError::Value
naming the rule — a detector that silently fails to compile would be
a redaction hole.
Sourcepub fn detect(&self, text: &str) -> Vec<Finding>
pub fn detect(&self, text: &str) -> Vec<Finding>
Run every detector over text, returning non-overlapping findings in
text order. Where a named match and an entropy run overlap, the named
match wins when they start together; otherwise the earlier span wins
(the secret is still covered either way).
Sourcepub fn redact_text(&self, text: &str) -> Option<RedactedText>
pub fn redact_text(&self, text: &str) -> Option<RedactedText>
Redact text, replacing every finding with its token. Returns None
when the text is clean (no allocation, no rewrite). The returned text
is a fixed point: re-detecting it finds nothing (the loop below runs
until clean; each pass strictly shrinks the surviving original text,
and replacement tokens never re-match, so it terminates).
Sourcepub fn redact_json(&self, value: &mut Value) -> Vec<Finding>
pub fn redact_json(&self, value: &mut Value) -> Vec<Finding>
Redact every string scalar in a JSON tree in place, returning the
findings (spans are relative to each individual string). Structured
payloads must be redacted on the parsed tree, not the encoded text,
for two reasons: hash8 must be computed over the raw secret bytes
(a hash over the \n-escaped encoding would not correlate with the
same secret seen in plain text), and splicing tokens into encoded
text could split an escape sequence and corrupt the stored JSON.
Object keys are not rewritten (they are structural, and a
secret-as-key does not occur in data Halfhand writes).
Sourcepub fn detect_json(&self, value: &Value) -> Vec<Finding>
pub fn detect_json(&self, value: &Value) -> Vec<Finding>
Detect over a JSON tree without mutating it (the hh scan path).
Sourcepub fn redact_bytes(&self, content: &[u8]) -> Option<RedactedBytes>
pub fn redact_bytes(&self, content: &[u8]) -> Option<RedactedBytes>
Redact raw content (a blob): JSON-aware when the bytes parse as JSON
(see Self::redact_json for why), plain text otherwise. Returns
None when the content is clean or not UTF-8 (binary content is not
scanned — a documented limitation).
Sourcepub fn detect_bytes(&self, content: &[u8]) -> Vec<Finding>
pub fn detect_bytes(&self, content: &[u8]) -> Vec<Finding>
Detect over raw content without mutating it (the hh scan path):
JSON-aware when it parses, plain text when UTF-8, skipped otherwise.