Skip to main content

ScannerConfig

Struct ScannerConfig 

Source
pub struct ScannerConfig {
    pub scan: ScanConfig,
    pub entropy_bpe_max_bytes_per_token_override: Option<f64>,
    pub ml_weight_override: Option<f64>,
    pub multiline: MultilineConfig,
    pub penalize_test_paths: bool,
    pub per_chunk_timeout_ms: Option<u64>,
    pub profile: bool,
    pub perf_trace: bool,
    pub calibration: Option<Arc<Calibration>>,
}
Expand description

Scanner-side configuration: the canonical ScanConfig, the single owned source of truth for every shared detection knob (decode depth, entropy, ML, confidence floor, keyword lists, …). PLUS the two knobs that are scanner-crate-local and have no place on keyhog-core’s ScanConfig:

  • multiline: its type ([crate::multiline::MultilineConfig]) is defined in THIS crate, and keyhog-core cannot depend on keyhog-scanner without a dependency cycle, so the field cannot live on ScanConfig.
  • penalize_test_paths: a scanner-internal suppression toggle the CLI flips for --no-suppress-test-fixtures; it never appears on the on-disk config.

This is the “thin newtype over ScanConfig” MC-01 calls for. It deliberately does not restate any of ScanConfig’s fields: every shared knob is read and written straight through Deref/DerefMut (config.min_confidence, config.entropy_enabled, config.known_prefixes, …), so there is exactly ONE definition of each, no parallel field list that can drift, and the From<ScanConfig> impl below is a structural wrap, never a hand-maintained field-by-field copy.

ScanConfig’s max_file_size / dedup fields are reachable through the deref but are NOT consumed by the scan engine, they are enforced elsewhere (the source walker and the verifier) and carry that caveat in their own doc comments on ScanConfig. Their presence here is the wrapped truth, not a second silent copy. min_secret_len is consumed by the entropy fallback.

Fields§

§scan: ScanConfig

The canonical shared detection config, single source of truth for every knob the engine and CLI agree on. Reached transparently via Deref, so callers write config.min_confidence, not config.scan.min_confidence.

§entropy_bpe_max_bytes_per_token_override: Option<f64>

Explicit Tier-A scan override for detector-local BPE policy. None means each detector TOML owns its ceiling and the wrapped ScanConfig value is only the compatibility fallback. Some means TOML/CLI scan configuration explicitly requested one ceiling for every eligible detector; CLI/config presence is preserved so precedence remains compiled default -> detector TOML -> scan TOML -> CLI.

§ml_weight_override: Option<f64>

Explicit Tier-A override for detector-local ML scoring weights. None keeps each detector TOML authoritative; presence applies one diagnostic or benchmarking override across eligible detector paths.

§multiline: MultilineConfig

Configuration for multiline concatenation (scanner-local type).

§penalize_test_paths: bool

Apply test/example path confidence and hard-suppression heuristics. The CLI disables this for --no-suppress-test-fixtures.

§per_chunk_timeout_ms: Option<u64>

Optional caller-resolved per-chunk scan deadline in milliseconds.

§profile: bool

Emit the scanner-owned hierarchical profile report to stderr.

§perf_trace: bool

Emit low-level phase timing traces for GPU/perf investigation.

§calibration: Option<Arc<Calibration>>

Explicit per-detector Bayesian calibration store. Absent means the scan is hermetic and score-stable; the scanner never reads a default disk cache on its own because that would make findings depend on stray host state.

Implementations§

Source§

impl ScannerConfig

Source

pub const HIGH_PRECISION_MIN_CONFIDENCE: f64 = 0.85

Confidence floor for ScannerConfig::high_precision. Distinct from the canonical ScanConfig::default() floor (0.40) on purpose: precision mode trades recall for a near-zero false-positive rate at mass-scan scale.

Source

pub const DEEP_MAX_DECODE_BYTES: usize = crate::types::MAX_SCAN_CHUNK_BYTES

Deep mode admits one complete production scan chunk into decode-through. The default stays at 512 KiB to bound routine work; deep intentionally spends more memory and CPU to recover encoded values anywhere in a filesystem window.

Source

pub fn fast() -> Self

Source

pub fn thorough() -> Self

Source

pub fn high_precision() -> Self

High-precision mass-scan preset: minimise false positives at the cost of some recall, for scanning huge corpora where every FP is expensive to triage. Fully offline, with ML confidence scoring, no entropy sweep, and shallow decode.

  • entropy_enabled = false: generic high-entropy matching is the single largest FP source; precision mode drops it entirely.
  • ml_enabled = true (inherited): ML is the confidence discriminator that lifts genuine secrets over the high floor while leaving FP-shaped tokens below it. Disabling it would crater the scores the 0.85 bar relies on, so precision KEEPS ML (this mode trades recall for precision, not for speed (use --fast when speed is the goal)).
  • min_confidence = HIGH_PRECISION_MIN_CONFIDENCE (0.85): combined with the engine’s checksum policy (valid token → floored 0.9, invalid → capped 0.1) and clamped over every detector’s self-declared floor, this bar admits checksum-validated tokens and strong ML-scored findings while dropping checksum-failures and weak-signal matches.
  • max_decode_depth = 1: deep-decoded payloads are a FP source at scale.

penalize_test_paths stays on (the default) to suppress fixture-shaped hits. A --min-confidence override still layers on top of this preset.

Source

pub fn min_confidence(self, min_confidence: f64) -> Self

Source

pub fn sanitise(&mut self)

Clamp every float field into its valid range and replace any NaN with a safe default. A user-supplied --min-confidence=-5.0 or a corrupt config TOML feeding min_confidence = nan would otherwise NaN-infect the confidence-comparison path and silently drop every finding (NaN comparisons are always false, so conf < min_confidence is false, but conf >= min_confidence is also false, behaviour-dependent on the call site).

Idempotent - sanitising an already-sane config is a no-op. Called inside From<ScanConfig> so any path that constructs a ScannerConfig from a user-influenced source pays this once at config-build time.

Source

pub fn with_calibration(self, calibration: Arc<Calibration>) -> Self

Source

pub fn with_entropy_bpe_max_bytes_per_token_override( self, bound: f64, ) -> Result<Self, ConfigError>

Set an explicit scan-wide BPE ceiling while preserving presence even when bound equals the compiled fallback. Library callers should use this instead of relying on From<ScanConfig> when they intend a value of 2.2 to override detector-local TOML policy: ScanConfig stores only the number and cannot distinguish “omitted default” from “explicitly set to the default.” The complete shared scan config is validated before the override is accepted, so invalid programmatic policy fails closed.

Source

pub fn with_ml_weight_override(self, weight: f64) -> Result<Self, ConfigError>

Set an explicit scan-wide model-weight override. Ordinary scans should leave this absent so detector TOMLs retain their calibrated weights.

Methods from Deref<Target = ScanConfig>§

Source

pub fn validate(&self) -> Result<(), ConfigError>

Validate the configuration parameters, failing closed on any value that would silently break scanning. This is the “separate later step” the deserialize path deliberately omits (see the regression_scan_config_fields contract): ScanConfig::from_toml_str composes deserialize + this into one validated load, and a library consumer who builds a ScanConfig by hand calls it directly before handing the config to the engine.

Every check is NaN-safe: RangeInclusive::contains is false for NaN (so a NaN bound is rejected, not silently admitted), and the entropy checks reject non-finite values explicitly.

Trait Implementations§

Source§

impl Clone for ScannerConfig

Source§

fn clone(&self) -> ScannerConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScannerConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ScannerConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for ScannerConfig

Source§

type Target = ScanConfig

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ScanConfig

Dereferences the value.
Source§

impl DerefMut for ScannerConfig

Source§

fn deref_mut(&mut self) -> &mut ScanConfig

Mutably dereferences the value.
Source§

impl From<ScanConfig> for ScannerConfig

Source§

fn from(scan: ScanConfig) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more