Skip to main content

stix_rs/observables/
software.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4#[serde(rename_all = "snake_case")]
5pub struct Software {
6    pub name: Option<String>,
7    pub cpe: Option<String>,
8    pub lang: Option<String>,
9    #[serde(flatten)]
10    pub custom_properties: std::collections::HashMap<String, serde_json::Value>,
11}
12
13impl Software {
14    pub fn builder() -> SoftwareBuilder {
15        SoftwareBuilder::default()
16    }
17}
18
19#[derive(Debug, Default)]
20pub struct SoftwareBuilder {
21    name: Option<String>,
22    cpe: Option<String>,
23    lang: Option<String>,
24    custom_properties: std::collections::HashMap<String, serde_json::Value>,
25}
26
27impl SoftwareBuilder {
28    pub fn name(mut self, n: impl Into<String>) -> Self {
29        self.name = Some(n.into());
30        self
31    }
32    pub fn cpe(mut self, c: impl Into<String>) -> Self {
33        self.cpe = Some(c.into());
34        self
35    }
36    pub fn lang(mut self, l: impl Into<String>) -> Self {
37        self.lang = Some(l.into());
38        self
39    }
40    pub fn property(mut self, k: impl Into<String>, v: impl Into<serde_json::Value>) -> Self {
41        self.custom_properties.insert(k.into(), v.into());
42        self
43    }
44    pub fn build(self) -> Software {
45        Software {
46            name: self.name,
47            cpe: self.cpe,
48            lang: self.lang,
49            custom_properties: self.custom_properties,
50        }
51    }
52}
53
54impl From<Software> for crate::StixObjectEnum {
55    fn from(s: Software) -> Self {
56        crate::StixObjectEnum::Software(s)
57    }
58}