pub struct CompiledScanner { /* private fields */ }Expand description
The compiled scanner: all detector patterns fused into a single Aho-Corasick automaton for prefiltering, backed by individual regexes for extraction.
§Examples
use keyhog_core::{Chunk, ChunkMetadata, DetectorSpec, PatternSpec, Severity};
use keyhog_scanner::CompiledScanner;
let scanner = CompiledScanner::compile(vec![DetectorSpec {
id: "demo-token".into(),
name: "Demo Token".into(),
service: "demo".into(),
severity: Severity::High,
patterns: vec![PatternSpec {
regex: "demo_[A-Z0-9]{8}".into(),
description: None,
group: None,
}],
companion: None,
verify: None,
keywords: vec!["demo_".into()],
}])
.unwrap();
let chunk = Chunk {
data: "TOKEN=demo_ABC12345".into(),
metadata: ChunkMetadata {
source_type: "filesystem".into(),
path: Some(".env".into()),
commit: None,
author: None,
date: None,
},
};
assert_eq!(scanner.scan(&chunk).len(), 1);Implementations§
Source§impl CompiledScanner
impl CompiledScanner
Sourcepub fn compile(detectors: Vec<DetectorSpec>) -> Result<Self, ScanError>
pub fn compile(detectors: Vec<DetectorSpec>) -> Result<Self, ScanError>
Compile all detector specs into a single scanner.
§Examples
use keyhog_core::{DetectorSpec, PatternSpec, Severity};
use keyhog_scanner::CompiledScanner;
let scanner = CompiledScanner::compile(vec![DetectorSpec {
id: "demo-token".into(),
name: "Demo Token".into(),
service: "demo".into(),
severity: Severity::High,
patterns: vec![PatternSpec {
regex: "demo_[A-Z0-9]{8}".into(),
description: None,
group: None,
}],
companion: None,
verify: None,
keywords: vec!["demo_".into()],
}])
.unwrap();
assert_eq!(scanner.detector_count(), 1);Sourcepub fn detector_count(&self) -> usize
pub fn detector_count(&self) -> usize
Number of loaded detectors.
§Examples
use keyhog_core::{DetectorSpec, PatternSpec, Severity};
use keyhog_scanner::CompiledScanner;
let scanner = CompiledScanner::compile(vec![DetectorSpec {
id: "demo-token".into(),
name: "Demo Token".into(),
service: "demo".into(),
severity: Severity::High,
patterns: vec![PatternSpec {
regex: "demo_[A-Z0-9]{8}".into(),
description: None,
group: None,
}],
companion: None,
verify: None,
keywords: vec!["demo_".into()],
}])
.unwrap();
assert_eq!(scanner.detector_count(), 1);Sourcepub fn pattern_count(&self) -> usize
pub fn pattern_count(&self) -> usize
Total number of patterns (AC + fallback).
§Examples
use keyhog_core::{DetectorSpec, PatternSpec, Severity};
use keyhog_scanner::CompiledScanner;
let scanner = CompiledScanner::compile(vec![DetectorSpec {
id: "demo-token".into(),
name: "Demo Token".into(),
service: "demo".into(),
severity: Severity::High,
patterns: vec![PatternSpec {
regex: "demo_[A-Z0-9]{8}".into(),
description: None,
group: None,
}],
companion: None,
verify: None,
keywords: vec!["demo_".into()],
}])
.unwrap();
assert_eq!(scanner.pattern_count(), 1);Sourcepub fn scan(&self, chunk: &Chunk) -> Vec<RawMatch>
pub fn scan(&self, chunk: &Chunk) -> Vec<RawMatch>
Scan a chunk of text and return all raw credential matches. Applies multi-line preprocessing to detect secrets split across lines. Large chunks are split into overlapping windows for bounded scan time.
§Examples
use keyhog_core::{Chunk, ChunkMetadata, DetectorSpec, PatternSpec, Severity};
use keyhog_scanner::CompiledScanner;
let scanner = CompiledScanner::compile(vec![DetectorSpec {
id: "demo-token".into(),
name: "Demo Token".into(),
service: "demo".into(),
severity: Severity::High,
patterns: vec![PatternSpec {
regex: "demo_[A-Z0-9]{8}".into(),
description: None,
group: None,
}],
companion: None,
verify: None,
keywords: vec!["demo_".into()],
}])
.unwrap();
let matches = scanner.scan(&Chunk {
data: "TOKEN=demo_ABC12345".into(),
metadata: ChunkMetadata {
source_type: "filesystem".into(),
path: Some(".env".into()),
commit: None,
author: None,
date: None,
},
});
assert_eq!(matches.len(), 1);Auto Trait Implementations§
impl Freeze for CompiledScanner
impl RefUnwindSafe for CompiledScanner
impl Send for CompiledScanner
impl Sync for CompiledScanner
impl Unpin for CompiledScanner
impl UnsafeUnpin for CompiledScanner
impl UnwindSafe for CompiledScanner
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
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>
Converts
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>
Converts
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 more