Skip to main content

Crate truman

Crate truman 

Source
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, &registry, &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§

DetectorContext
Per-line context handed to every detector.
DetectorRegistry
Thread-safe registry of detectors.
FileStats
Per-file statistics emitted with ScanEvent::FileDone.
FilterConfig
Which filters are enabled, plus exclusion patterns.
FilterSet
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.
ScanConfig
How to scan.
Scanner
The scanner: registry + config + filter set.
Span
Byte-exact position of a secret within a single line.

Enums§

FileType
File type derived from a file’s extension.
ScanEvent
Streaming scan events.
TrumanError
Top-level error type for the truman workspace.
VerifiedResult
Result of (optional) external verification of a secret.

Constants§

VERSION
Crate version (mirrors workspace version).

Traits§

Detector
The core extension point of truman.
FileFilter
Line-level filter trait (staged pipeline).
LineFilter
Line-level filter trait (staged pipeline).
SecretFilter
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 HexHighEntropyString integer penalty:
is_allowlisted
True if line carries a same-line allowlist pragma, or prev_line carries a nextline pragma for this line.
is_indirect_reference
True for indirect references like secret = get_secret_key() or secret = request.headers['apikey'].
is_invalid_file
True if path is 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 Python is_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_uuid with re.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 spec len<=1 → true).
scan_paths_collect
Convenience collect wrapper: build a Scanner from registry + config and return all findings via Scanner::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 against charset.
shannon_entropy_bytes
Byte-oriented variant; charset is a byte set.
should_exclude_due_to_verification_policy
Verification-policy stage (mirrors is_ignored_due_to_verification_policies).
should_exclude_file
True if filename matches any exclude-files pattern.
should_exclude_line
True if line matches any exclude-lines pattern.
should_exclude_secret
True if secret matches any exclude-secrets pattern.

Type Aliases§

Result
Convenience alias.
ScanCallback
Streaming callback: receives ScanEvents, returns true to continue or false to abort early.