#![allow(dead_code)]
use super::authoring::{Reference, Severity};
use std::collections::BTreeSet;
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HostDetection {
pub detection: HostManifest,
#[serde(default)]
pub finding: Vec<FindingSpec>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HostManifest {
pub id: String,
pub version: String,
pub title: String,
pub host: HostGate,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct HostGate {
#[serde(default)]
pub ports_open: Vec<u16>,
#[serde(default)]
pub services: Vec<String>,
}
impl HostGate {
pub(crate) fn matches(&self, open_ports: &BTreeSet<u16>, services: &BTreeSet<&str>) -> bool {
self.ports_open.iter().all(|port| open_ports.contains(port))
&& self
.services
.iter()
.all(|service| services.contains(service.as_str()))
}
}
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FindingSpec {
pub severity: Severity,
pub summary: String,
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub detail: Option<String>,
#[serde(default)]
pub confidence: Option<String>,
#[serde(default)]
pub references: Vec<Reference>,
#[serde(default)]
pub remediation: Option<String>,
}