pub struct PatternSpec {
pub regex: String,
pub description: Option<String>,
pub group: Option<usize>,
pub required_literals: Vec<String>,
pub client_safe: bool,
pub weak_anchor: bool,
pub structural_password_slot: bool,
}Expand description
A regex pattern with optional capture group and description.
Fields§
§regex: StringRegular expression string (Rust flavor). The owning detector TOML defines its exact separator and quantifier semantics; loading never rewrites the expression.
description: Option<String>Optional context description.
group: Option<usize>Optional capture group index containing the secret.
required_literals: Vec<String>ASCII literals used only for candidate routing. Every full regex match must contain at least one declared literal; detector validation proves that OR-condition from the regex AST before the corpus can load.
client_safe: boolWhen true, a match against THIS pattern downgrades the
finding to Severity::ClientSafe (regardless of the detector’s
nominal severity). Used by services that intentionally ship
public-facing keys in client bundles:
- Sentry DSN (the
https://<key>@URL is meant for the browser) - Stripe
pk_live_/pk_test_(publishable, sk_ is secret) - Mapbox
pk.(public,sk.is secret) - Firebase Web API key, Google Maps browser key
- PostHog / Mixpanel / Algolia search / Datadog browser RUM
Per-pattern (not per-detector) so detectors that fire on both the public and the secret prefix can tag only the public one.
Case sensitivity: keyhog compiles every regex case_insensitive(true),
so to make a single pattern case-SENSITIVE (AWS AKIA is uppercase,
GCP/Snowflake ids are lowercase) prefix its regex with the inline flag
(?-i) in the TOML - no schema field needed.
weak_anchor: boolKeep generic shape and entropy gates active for matches from this
pattern. Declare this beside the regex so policy cannot drift when a
detector’s patterns are reordered. Detector-level weak_anchor = true
applies the same policy to every pattern.
structural_password_slot: boolTreat matches from this exact regex as syntactically proven password slots. Unlike the detector-level flag, this does not exempt generic keyword-bridge candidates or sibling patterns from Tier-B shape gates.
Implementations§
Source§impl PatternSpec
impl PatternSpec
Sourcepub fn validate_required_literals(&self) -> Result<(), String>
pub fn validate_required_literals(&self) -> Result<(), String>
Validate that the declared routing literals are a necessary OR-condition of every regex match. The proof is conservative: declarations that span optional or structurally ambiguous AST nodes are rejected.
Trait Implementations§
Source§impl Clone for PatternSpec
impl Clone for PatternSpec
Source§fn clone(&self) -> PatternSpec
fn clone(&self) -> PatternSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PatternSpec
impl Debug for PatternSpec
Source§impl Default for PatternSpec
impl Default for PatternSpec
Source§fn default() -> PatternSpec
fn default() -> PatternSpec
Source§impl<'de> Deserialize<'de> for PatternSpec
impl<'de> Deserialize<'de> for PatternSpec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for PatternSpec
impl PartialEq for PatternSpec
Source§impl Serialize for PatternSpec
impl Serialize for PatternSpec
impl StructuralPartialEq for PatternSpec
Auto Trait Implementations§
impl Freeze for PatternSpec
impl RefUnwindSafe for PatternSpec
impl Send for PatternSpec
impl Sync for PatternSpec
impl Unpin for PatternSpec
impl UnsafeUnpin for PatternSpec
impl UnwindSafe for PatternSpec
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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>
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>
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