keyhog_scanner/context/
mod.rs1mod documentation;
9mod false_positive;
10mod inference;
11
12pub use documentation::documentation_line_flags;
13pub use false_positive::{
14 is_false_positive_context, is_false_positive_context_with_path, is_false_positive_match_context,
15};
16pub use inference::{
17 infer_context, infer_context_with_documentation, infer_context_with_regions,
18 is_known_example_credential, is_sequential_placeholder, ContextRegions,
19};
20
21const ASSIGNMENT_CONFIDENCE_MULTIPLIER: f64 = 1.0;
22const STRING_LITERAL_CONFIDENCE_MULTIPLIER: f64 = 0.9;
23const UNKNOWN_CONFIDENCE_MULTIPLIER: f64 = 0.8;
24const DOCUMENTATION_CONFIDENCE_MULTIPLIER: f64 = 0.3;
25const COMMENT_CONFIDENCE_MULTIPLIER: f64 = 0.4;
26const TEST_CODE_CONFIDENCE_MULTIPLIER: f64 = 0.3;
27const ENCRYPTED_CONFIDENCE_MULTIPLIER: f64 = 0.05;
28
29#[derive(Debug, Clone, Copy, PartialEq)]
31pub enum CodeContext {
32 Assignment,
34 Comment,
36 TestCode,
38 Encrypted,
40 Documentation,
42 StringLiteral,
44 Unknown,
46}
47
48impl CodeContext {
49 pub fn confidence_multiplier(&self) -> f64 {
51 match self {
52 Self::Assignment => ASSIGNMENT_CONFIDENCE_MULTIPLIER,
53 Self::StringLiteral => STRING_LITERAL_CONFIDENCE_MULTIPLIER,
54 Self::Unknown => UNKNOWN_CONFIDENCE_MULTIPLIER,
55 Self::Documentation => DOCUMENTATION_CONFIDENCE_MULTIPLIER,
56 Self::Comment => COMMENT_CONFIDENCE_MULTIPLIER,
57 Self::TestCode => TEST_CODE_CONFIDENCE_MULTIPLIER,
58 Self::Encrypted => ENCRYPTED_CONFIDENCE_MULTIPLIER,
59 }
60 }
61
62 pub fn should_hard_suppress(&self, confidence: f64) -> bool {
64 match self {
65 Self::Documentation | Self::TestCode | Self::Comment => confidence < 0.5,
66 Self::Encrypted => confidence < 0.8,
67 _ => false,
68 }
69 }
70}