clamav_tcp/
responses.rs

1use serde::{Deserialize, Serialize};
2
3use crate::ClamAVClientError;
4use std::str::FromStr;
5
6/// A struct that describes the result of the scan.
7#[derive(Deserialize, Debug, Serialize)]
8pub struct ScanResult {
9    /// If a malicious file was found within the scanned item.
10    pub is_infected: bool,
11    /// Names of the detected infections.
12    pub detected_infections: Vec<String>,
13}
14
15impl FromStr for ScanResult {
16    type Err = ClamAVClientError;
17
18    fn from_str(s: &str) -> Result<Self, Self::Err> {
19        // Take section after "stream: "
20        let stuff: Vec<&str> = s.split("stream: ").into_iter().skip(1).collect();
21        if stuff.clone().into_iter().any(|x| x.starts_with("OK")) {
22            return Ok(ScanResult {
23                is_infected: false,
24                detected_infections: vec![],
25            });
26        }
27
28        let detections = stuff
29            .into_iter()
30            .map(|e| e.to_string().replace(" FOUND\0", ""))
31            .collect();
32        Ok(ScanResult {
33            is_infected: true,
34            detected_infections: detections,
35        })
36    }
37}