use regex::Regex;
pub struct AttackStructures {
named: Vec<(&'static str, Regex)>,
}
impl AttackStructures {
#[must_use]
pub fn named(&self) -> &[(&'static str, Regex)] {
&self.named
}
pub fn compiled(&self) -> impl Iterator<Item = &Regex> {
self.named.iter().map(|(_, re)| re)
}
}
impl Default for AttackStructures {
fn default() -> Self {
let definitions: &[(&str, &str)] = &[
("tag_like", r"<[^>]+>"),
("function_call", r"\w+\s*\([^)]*\)"),
("command_chain", r"[;&|]{1,2}"),
("path_traversal", r"\.{2,}[/\\]"),
("url_pattern", r"[a-z]+://"),
];
let named = definitions
.iter()
.map(|&(name, pat)| {
let re = Regex::new(&format!("(?i){pat}")).expect("static pattern must compile");
(name, re)
})
.collect();
Self { named }
}
}