Skip to main content

Allowlist

Struct Allowlist 

Source
pub struct Allowlist {
    pub credential_hashes: HashSet<[u8; 32]>,
    pub ignored_detectors: HashSet<String>,
    pub ignored_paths: Vec<String>,
}
Expand description

User-defined suppressions loaded from .keyhogignore: credential hashes, detector IDs, and path globs.

§Examples

use keyhog_core::allowlist::Allowlist;

let allowlist = Allowlist::parse("detector:demo-token\npath:**/*.md\n");
assert!(allowlist.ignored_detectors.contains("demo-token"));

Fields§

§credential_hashes: HashSet<[u8; 32]>

SHA-256 hashes of credentials to ignore.

§ignored_detectors: HashSet<String>

Detector IDs to ignore entirely.

§ignored_paths: Vec<String>

Glob patterns for paths to ignore.

Implementations§

Source§

impl Allowlist

Source

pub fn empty() -> Self

Create an empty allowlist with no suppressed hashes, detectors, or paths.

§Examples
use keyhog_core::allowlist::Allowlist;

let allowlist = Allowlist::empty();
assert!(allowlist.ignored_paths.is_empty());
Source

pub fn load(path: &Path) -> Result<Self, Error>

Load from a .keyhogignore file.

§Examples
use keyhog_core::allowlist::Allowlist;
use std::path::Path;

let _allowlist = Allowlist::load(Path::new(".keyhogignore")).unwrap();
Source

pub fn parse(content: &str) -> Self

Parse allowlist from string content.

§Examples
use keyhog_core::allowlist::Allowlist;

let allowlist = Allowlist::parse("path:**/.env\ndetector:demo-token\n");
assert!(allowlist.is_path_ignored("app/.env"));
Examples found in repository?
examples/core_standalone.rs (line 24)
7fn main() {
8    let detector = DetectorSpec {
9        id: "demo-token".into(),
10        name: "Demo Token".into(),
11        service: "demo".into(),
12        severity: Severity::High,
13        patterns: vec![PatternSpec {
14            regex: "demo_[A-Z0-9]{8}".into(),
15            description: Some("Simple standalone example".into()),
16            group: None,
17        }],
18        companion: None,
19        verify: None,
20        keywords: vec!["demo_".into()],
21    };
22
23    let issues = validate_detector(&detector);
24    let allowlist = Allowlist::parse("path:**/*.md\n");
25    let maybe_detectors = load_detectors_with_gate(Path::new("detectors"), true).ok();
26
27    println!("detector={} issues={}", detector.id, issues.len());
28    println!("redacted={}", redact("demo_ABC12345"));
29    println!(
30        "ignores_docs={}",
31        allowlist.is_path_ignored("docs/README.md")
32    );
33    println!(
34        "workspace_detectors_loaded={}",
35        maybe_detectors.as_ref().map_or(0, Vec::len)
36    );
37}
Source

pub fn is_allowed(&self, finding: &VerifiedFinding) -> bool

Check whether detector or path rules suppress a verified finding.

Hash-based suppression is evaluated earlier on crate::RawMatch values because VerifiedFinding stores only redacted credentials.

§Examples
use keyhog_core::allowlist::Allowlist;
use keyhog_core::{MatchLocation, Severity, VerificationResult, VerifiedFinding};
use std::collections::HashMap;

let allowlist = Allowlist::parse("detector:demo-token\n");
let finding = VerifiedFinding {
    detector_id: "demo-token".into(),
    detector_name: "Demo Token".into(),
    service: "demo".into(),
    severity: Severity::High,
    credential_redacted: "demo_...1234".into(),
    location: MatchLocation {
        source: "filesystem".into(),
        file_path: Some(".env".into()),
        line: Some(1),
        offset: 0,
        commit: None,
        author: None,
        date: None,
    },
    verification: VerificationResult::Skipped,
    metadata: HashMap::new(),
    additional_locations: Vec::new(),
    confidence: None,
};

assert!(allowlist.is_allowed(&finding));
Source

pub fn is_hash_allowed(&self, credential: &str) -> bool

Check if a raw credential hash is allowlisted.

§Examples
use keyhog_core::allowlist::Allowlist;

let allowlist = Allowlist::parse("");
assert!(!allowlist.is_hash_allowed("demo_ABC12345"));
Source

pub fn is_path_ignored(&self, path: &str) -> bool

Check whether a raw path matches an ignored-path glob.

§Examples
use keyhog_core::allowlist::Allowlist;

let allowlist = Allowlist::parse("path:**/*.md\n");
assert!(allowlist.is_path_ignored("docs/README.md"));
Examples found in repository?
examples/core_standalone.rs (line 31)
7fn main() {
8    let detector = DetectorSpec {
9        id: "demo-token".into(),
10        name: "Demo Token".into(),
11        service: "demo".into(),
12        severity: Severity::High,
13        patterns: vec![PatternSpec {
14            regex: "demo_[A-Z0-9]{8}".into(),
15            description: Some("Simple standalone example".into()),
16            group: None,
17        }],
18        companion: None,
19        verify: None,
20        keywords: vec!["demo_".into()],
21    };
22
23    let issues = validate_detector(&detector);
24    let allowlist = Allowlist::parse("path:**/*.md\n");
25    let maybe_detectors = load_detectors_with_gate(Path::new("detectors"), true).ok();
26
27    println!("detector={} issues={}", detector.id, issues.len());
28    println!("redacted={}", redact("demo_ABC12345"));
29    println!(
30        "ignores_docs={}",
31        allowlist.is_path_ignored("docs/README.md")
32    );
33    println!(
34        "workspace_detectors_loaded={}",
35        maybe_detectors.as_ref().map_or(0, Vec::len)
36    );
37}

Trait Implementations§

Source§

impl Clone for Allowlist

Source§

fn clone(&self) -> Allowlist

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Allowlist

Source§

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

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

impl Serialize for Allowlist

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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