1use crate::object::WafMap;
2use crate::waf_map;
3
4#[derive(Clone, Default, Debug)]
6pub struct Config {
7 obfuscator: Obfuscator,
8}
9impl Config {
10 #[must_use]
12 pub fn new(obfuscator: Obfuscator) -> Self {
13 Self { obfuscator }
14 }
15
16 #[must_use]
21 pub fn as_waf_object(&self) -> WafMap {
22 let mut map = WafMap::new(2).expect("configuration map length is representable");
23 let mut used = 0;
24 if let Some(key_regex) = self.obfuscator.key_regex() {
25 map[used] = ("key_regex", key_regex).into();
26 used += 1;
27 }
28 if let Some(value_regex) = self.obfuscator.value_regex() {
29 map[used] = ("value_regex", value_regex).into();
30 used += 1;
31 }
32 map.truncate(used);
33
34 waf_map!(("obfuscator", map))
35 }
36}
37
38#[derive(Clone, Debug)]
44pub struct Obfuscator {
45 key_regex: Option<Vec<u8>>,
46 value_regex: Option<Vec<u8>>,
47}
48impl Obfuscator {
49 pub fn new<T: Into<Vec<u8>>, U: Into<Vec<u8>>>(
55 key_regex: Option<T>,
56 value_regex: Option<U>,
57 ) -> Self {
58 Self {
59 key_regex: key_regex.map(Into::into),
60 value_regex: value_regex.map(Into::into),
61 }
62 }
63
64 #[must_use]
67 pub fn key_regex(&self) -> Option<&[u8]> {
68 self.key_regex.as_deref()
69 }
70
71 #[must_use]
74 pub fn value_regex(&self) -> Option<&[u8]> {
75 self.value_regex.as_deref()
76 }
77}
78
79impl Default for Obfuscator {
80 fn default() -> Self {
81 Obfuscator::new(None::<&str>, None::<&str>)
83 }
84}