mod helpers;
mod matching;
pub use helpers::{parse_expand_template, sigma_string_to_regex};
use regex::Regex;
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),
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>),
}
#[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))
}
}