Skip to main content

CredentialScanner

Struct CredentialScanner 

Source
pub struct CredentialScanner { /* private fields */ }
Expand description

Pre-compiled multi-pattern credential scanner.

Construct once with CredentialScanner::new (or CredentialScanner::with_config) and call CredentialScanner::scan repeatedly. Pattern compilation happens at construction time; each scan call is O(n) in the length of the input text.

Implementations§

Source§

impl CredentialScanner

Source

pub fn new() -> Self

Build the scanner with all built-in patterns and scanning enabled.

§Panics

Panics only if the hard-coded AC patterns are somehow invalid — this cannot happen in practice.

Source

pub fn with_config(config: ScannerConfig) -> Self

Build the scanner from explicit configuration.

Custom patterns are appended after the built-in set and are tagged as CredentialKind::Custom. If config.disabled is true the scanner is inert — scan always returns an empty result.

Source

pub fn scan(&self, text: &str) -> ScanResult

Scan text for credential patterns and return a ScanResult.

Four passes are performed:

  1. Aho-Corasick literal prefix scan — O(n), 18 patterns covering API keys, auth tokens, cloud credentials, database URLs, and PEM private key headers.
  2. Credit card and SSN digit-sequence scan.
  3. Email address scan.
  4. High-entropy token scan (Shannon entropy > 4.5 bits/char, length 20–64).

Trait Implementations§

Source§

impl Default for CredentialScanner

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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, 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.