mod helpers;
mod matching;
pub use helpers::{ascii_lowercase_cow, parse_expand_template, sigma_string_to_regex};
use aho_corasick::AhoCorasick;
use regex::{Regex, RegexSet};
use crate::event::Event;
use ipnet::IpNet;
#[derive(Debug, Clone)]
pub enum CompiledMatcher {
Exact {
value: String,
case_insensitive: bool,
},
Contains {
value: String,
case_insensitive: bool,
},
StartsWith {
value: String,
case_insensitive: bool,
},
EndsWith {
value: String,
case_insensitive: bool,
},
Regex(Regex),
AhoCorasickSet {
automaton: AhoCorasick,
case_insensitive: bool,
needles: Vec<String>,
},
RegexSetMatch { set: RegexSet, mode: GroupMode },
Cidr(IpNet),
NumericEq(f64),
NumericGt(f64),
NumericGte(f64),
NumericLt(f64),
NumericLte(f64),
Exists(bool),
FieldRef {
field: String,
case_insensitive: bool,
},
Null,
BoolEq(bool),
Expand {
template: Vec<ExpandPart>,
case_insensitive: bool,
},
TimestampPart {
part: TimePart,
inner: Box<CompiledMatcher>,
},
Not(Box<CompiledMatcher>),
AnyOf(Vec<CompiledMatcher>),
AllOf(Vec<CompiledMatcher>),
CaseInsensitiveGroup {
children: Vec<CompiledMatcher>,
mode: GroupMode,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GroupMode {
Any,
All,
}
#[derive(Debug, Clone)]
pub enum ExpandPart {
Literal(String),
Placeholder(String),
}
#[derive(Debug, Clone, Copy)]
pub enum TimePart {
Minute,
Hour,
Day,
Week,
Month,
Year,
}
impl CompiledMatcher {
#[inline]
pub fn matches_keyword(&self, event: &impl Event) -> bool {
event.any_string_value(&|s| self.matches_str(s))
}
}