sentinel_modsec/operators/
traits.rs

1//! Operator trait definition.
2
3/// Result of operator execution.
4#[derive(Debug, Clone, Default)]
5pub struct OperatorResult {
6    /// Whether the operator matched.
7    pub matched: bool,
8    /// Captured groups from regex.
9    pub captures: Vec<String>,
10    /// The matched value.
11    pub matched_value: Option<String>,
12}
13
14impl OperatorResult {
15    /// Create a result indicating no match.
16    pub fn no_match() -> Self {
17        Self {
18            matched: false,
19            captures: Vec::new(),
20            matched_value: None,
21        }
22    }
23
24    /// Create a result indicating a match.
25    pub fn matched(value: String) -> Self {
26        Self {
27            matched: true,
28            captures: Vec::new(),
29            matched_value: Some(value),
30        }
31    }
32
33    /// Create a result with captures.
34    pub fn matched_with_captures(value: String, captures: Vec<String>) -> Self {
35        Self {
36            matched: true,
37            captures,
38            matched_value: Some(value),
39        }
40    }
41}
42
43/// Trait for all operators.
44pub trait Operator: Send + Sync {
45    /// Execute the operator against a value.
46    fn execute(&self, value: &str) -> OperatorResult;
47
48    /// Get the operator name.
49    fn name(&self) -> &'static str;
50
51    /// Whether this operator supports capture groups.
52    fn supports_capture(&self) -> bool {
53        false
54    }
55}