1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct PathPattern(pub String);
9
10impl PathPattern {
11 pub fn matches(&self, path: &str) -> bool {
12 glob_match(&self.0, path)
13 }
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18pub struct CommandPattern(pub String);
19
20impl CommandPattern {
21 pub fn matches(&self, program: &str) -> bool {
22 glob_match(&self.0, program)
23 }
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28pub struct NetworkPattern(pub String);
29
30impl NetworkPattern {
31 pub fn matches(&self, target: &str) -> bool {
32 glob_match(&self.0, target)
33 }
34}
35
36fn glob_match(pattern: &str, value: &str) -> bool {
38 if pattern == "*" {
39 return true;
40 }
41 if let Some(prefix) = pattern.strip_suffix('*') {
42 return value.starts_with(prefix);
43 }
44 if let Some(suffix) = pattern.strip_prefix('*') {
45 return value.ends_with(suffix);
46 }
47 pattern == value
48}