Expand description
truman: facade crate re-exporting core + detectors.
Downstream users depend only on this crate:
use truman::{default_registry, ScanConfig, Scanner};
let registry = default_registry();
let scanner = Scanner::new(registry, ScanConfig::default());
let findings = scanner.scan_paths(&["."]);
println!("found {}", findings.len());§Custom detector + streaming (prints without waiting for full scan)
use truman::{Detector, DetectorContext, RawFinding};
#[derive(Debug)] struct MyDetector;
impl Detector for MyDetector {
fn name(&self) -> &'static str { "MyDetector" }
fn secret_type(&self) -> &str { "My Secret" }
fn detect(&self, line: &str, _ctx: &DetectorContext) -> Vec<RawFinding> {
match line.find("hunter2") {
Some(s) => vec![RawFinding::new("hunter2".into(), s, s + 7)],
None => vec![],
}
}
}
use std::path::PathBuf;
use truman::{default_registry_with_config, scan_paths_streaming, ScanEvent};
let (mut registry, config) = default_registry_with_config();
registry.register(MyDetector);
let paths = vec![PathBuf::from(".")];
let mut cb = |ev: ScanEvent| {
if let ScanEvent::Finding(f) = ev {
println!("{}:{}: {}", f.location.file.display(), f.location.span.line, f.hashed_secret);
}
true
};
scan_paths_streaming(&paths, &config, ®istry, &mut cb);Modules§
- detector
- entropy
- Shannon entropy helpers for high-entropy detectors.
- error
- filetype
- filter
- Staged filter pipeline.
- finding
- scanner
- Parallel file scanner with streaming callbacks.
Structs§
- Detector
Context - Per-line context handed to every detector.
- Detector
Registry - Thread-safe registry of detectors.
- File
Stats - Per-file statistics emitted with
ScanEvent::FileDone. - Filter
Config - Which filters are enabled, plus exclusion patterns.
- Filter
Set - Staged filter set built from a
FilterConfig. - Finding
- A single detected potential secret.
- Location
- Where a finding was located.
- RawFinding
- A raw (unfiltered, unhashed) detector hit within a single line.
- Scan
Config - How to scan.
- Scanner
- The scanner: registry + config + filter set.
- Span
- Byte-exact position of a secret within a single line.
Enums§
- File
Type - File type derived from a file’s extension.
- Scan
Event - Streaming scan events.
- Truman
Error - Top-level error type for the truman workspace.
- Verified
Result - Result of (optional) external verification of a secret.
Constants§
- VERSION
- Crate version (mirrors workspace version).
Traits§
- Detector
- The core extension point of truman.
- File
Filter - Line-level filter trait (staged pipeline).
- Line
Filter - Line-level filter trait (staged pipeline).
- Secret
Filter - Secret-level filter trait (staged pipeline).
Functions§
- base64_
shannon_ entropy - Base64-ish entropy (letters + digits +
+/, url-safe-_, padding=). - default_
config - Default scan config (currently
ScanConfig::default). - default_
registry - Build the default registry: 140 detectors (27 detect-secrets originals + 113 gitleaks ports).
- default_
registry_ with_ config - Default registry + default config together.
- determine_
file_ type - Determine the file type from a path’s extension.
- hash_
secret - Compute lowercase SHA1 hex of the plaintext secret.
- hex_
shannon_ entropy - Hex entropy with the Python
HexHighEntropyStringinteger penalty: - is_
allowlisted - True if
linecarries a same-line allowlist pragma, orprev_linecarries a nextline pragma for this line. - is_
indirect_ reference - True for indirect references like
secret = get_secret_key()orsecret = request.headers['apikey']. - is_
invalid_ file - True if
pathis not an existing regular file. - is_
likely_ id_ string - True if the line looks like an
id-like key before the secret. - is_
likely_ id_ string_ at - True if the line looks like an
id-like key before the secret (mirrors Pythonis_likely_id_string). - is_
lock_ file - True for known lock files (mirrors Python
is_lock_file). - is_
non_ text_ file - True if the file has a known non-text extension.
- is_
not_ alphanumeric_ string - True if the secret contains no ASCII letter (e.g.
*****). - is_
potential_ uuid - True if the secret contains a UUID-shaped substring (case-insensitive,
mirrors Python
is_potential_uuidwithre.IGNORECASE). - is_
prefixed_ with_ dollar_ sign - True if the secret starts with
$(variable reference). - is_
regex_ based_ detector - Names of detectors that are NOT regex-based in Python terms.
- is_
sequential_ string - True if the upper-cased secret appears inside one of the known
sequential alphabets (mirrors Python
is_sequential_string). - is_
swagger_ file - True if the filename looks like a swagger asset.
- is_
templated_ secret - True for templated placeholders:
{x},<x>,${x}(plus degenerate 0/1-char inputs, mirroring the task speclen<=1 → true). - scan_
paths_ collect - Convenience collect wrapper: build a
Scannerfromregistry+configand return all findings viaScanner::scan_paths(dirs handled via Scanner’s walk). - scan_
paths_ streaming - Streaming scan over
paths(files or dirs). - shannon_
entropy - Shannon entropy of
data, measured againstcharset. - shannon_
entropy_ bytes - Byte-oriented variant;
charsetis a byte set. - should_
exclude_ due_ to_ verification_ policy - Verification-policy stage (mirrors
is_ignored_due_to_verification_policies). - should_
exclude_ file - True if
filenamematches any exclude-files pattern. - should_
exclude_ line - True if
linematches any exclude-lines pattern. - should_
exclude_ secret - True if
secretmatches any exclude-secrets pattern.
Type Aliases§
- Result
- Convenience alias.
- Scan
Callback - Streaming callback: receives
ScanEvents, returnstrueto continue orfalseto abort early.