Skip to main content

Detectors

Struct Detectors 

Source
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

Source

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.

Source

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).

Source

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).

Source

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).

Source

pub fn detect_json(&self, value: &Value) -> Vec<Finding>

Detect over a JSON tree without mutating it (the hh scan path).

Source

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).

Source

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.

Trait Implementations§

Source§

impl Debug for Detectors

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.