1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::collections::BTreeSet;
use serde::Deserialize;
use stix::{CommonProperties, Object};
use crate::get_mitre_id;
#[stix::custom_properties(namespace = "mitre")]
#[derive(Default, Deserialize)]
#[serde(default)]
pub struct MitreMalware {
pub aliases: BTreeSet<String>,
pub platforms: BTreeSet<String>,
}
#[derive(Deserialize, stix::TypedObject)]
pub struct Malware {
#[serde(flatten)]
pub base: stix::Malware,
#[serde(flatten)]
pub mitre: MitreMalware,
}
impl Malware {
pub fn name(&self) -> &str {
self.base.name()
}
pub fn description(&self) -> Option<&str> {
self.base.description()
}
pub fn mitre_id(&self) -> Option<&str> {
self.external_references().iter().find_map(get_mitre_id)
}
}
impl AsRef<CommonProperties> for Malware {
fn as_ref(&self) -> &CommonProperties {
self.base.as_ref()
}
}