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
44
45
46
47
48
49
50
51
52
53
use std::collections::BTreeSet;

use chrono::{DateTime, Utc};
use serde::Deserialize;

use crate::{
    vocab::{AttackMotivation, AttackResourceLevel},
    CommonProperties,
};

#[derive(Deserialize, stix_derive::TypedObject)]
#[typed_object(core)]
pub struct IntrusionSet {
    #[serde(flatten)]
    common: CommonProperties,
    name: String,
    #[serde(default)]
    description: Option<String>,
    #[serde(default)]
    aliases: BTreeSet<String>,
    #[serde(default)]
    pub first_seen: Option<DateTime<Utc>>,
    #[serde(default)]
    pub last_seen: Option<DateTime<Utc>>,
    #[serde(default)]
    pub goals: Vec<String>,
    #[serde(default)]
    pub resource_level: Option<AttackResourceLevel>,
    #[serde(default)]
    pub primary_motivation: Option<AttackMotivation>,
    #[serde(default)]
    pub secondary_motivations: BTreeSet<AttackMotivation>,
}

impl IntrusionSet {
    pub fn name(&self) -> &str {
        &self.name
    }

    pub fn description(&self) -> Option<&str> {
        self.description.as_ref().map(|s| s.as_str())
    }

    pub fn aliases(&self) -> &BTreeSet<String> {
        &self.aliases
    }
}

impl AsRef<CommonProperties> for IntrusionSet {
    fn as_ref(&self) -> &CommonProperties {
        &self.common
    }
}