stix_rs/sdos/
attack_pattern.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::common::{CommonProperties, StixObject};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub struct AttackPattern {
10 #[serde(flatten)]
11 pub common: CommonProperties,
12
13 pub name: String,
14 pub description: Option<String>,
15}
16
17impl AttackPattern {
18 pub fn builder() -> AttackPatternBuilder {
19 AttackPatternBuilder::default()
20 }
21}
22
23#[derive(Debug, Default)]
24pub struct AttackPatternBuilder {
25 name: Option<String>,
26 description: Option<String>,
27 created_by_ref: Option<String>,
28}
29
30impl AttackPatternBuilder {
31 pub fn name(mut self, name: impl Into<String>) -> Self {
32 self.name = Some(name.into());
33 self
34 }
35 pub fn description(mut self, d: impl Into<String>) -> Self {
36 self.description = Some(d.into());
37 self
38 }
39 pub fn created_by_ref(mut self, r: impl Into<String>) -> Self {
40 self.created_by_ref = Some(r.into());
41 self
42 }
43
44 pub fn build(self) -> Result<AttackPattern, super::BuilderError> {
45 let name = self.name.ok_or(super::BuilderError::MissingField("name"))?;
46 let common = CommonProperties::new("attack-pattern", self.created_by_ref);
47 Ok(AttackPattern {
48 common,
49 name,
50 description: self.description,
51 })
52 }
53}
54
55impl StixObject for AttackPattern {
56 fn id(&self) -> &str {
57 &self.common.id
58 }
59 fn type_(&self) -> &str {
60 &self.common.r#type
61 }
62 fn created(&self) -> DateTime<Utc> {
63 self.common.created
64 }
65}
66
67impl From<AttackPattern> for crate::StixObjectEnum {
68 fn from(a: AttackPattern) -> Self {
69 crate::StixObjectEnum::AttackPattern(a)
70 }
71}