open_detect/
scan_result.rs1type Detections = Vec<Detection>;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum ScanResult {
17 Clean,
19 Malicious(Detections),
21}
22
23impl From<yara_x::ScanResults<'_, '_>> for ScanResult {
24 fn from(results: yara_x::ScanResults) -> Self {
25 if results.matching_rules().len() == 0 {
26 ScanResult::Clean
27 } else {
28 let detections = results
29 .matching_rules()
30 .map(|rule| rule.identifier().into())
31 .collect();
32
33 ScanResult::Malicious(detections)
34 }
35 }
36}
37
38impl From<String> for ScanResult {
39 fn from(name: String) -> Self {
40 ScanResult::Malicious(vec![Detection { name }])
41 }
42}
43
44impl From<&str> for ScanResult {
45 fn from(name: &str) -> Self {
46 ScanResult::Malicious(vec![Detection {
47 name: name.to_string(),
48 }])
49 }
50}
51
52impl From<Vec<&str>> for ScanResult {
53 fn from(names: Vec<&str>) -> Self {
54 let detections = names
55 .into_iter()
56 .map(|name| Detection { name: name.into() })
57 .collect();
58 ScanResult::Malicious(detections)
59 }
60}
61
62#[derive(Debug, Clone, PartialEq, Eq)]
77pub struct Detection {
78 pub name: String,
80}
81
82impl From<&str> for Detection {
83 fn from(name: &str) -> Self {
84 Detection {
85 name: name.to_string(),
86 }
87 }
88}