1use std::fmt;
2
3use serde::Deserialize;
4
5use crate::CommonProperties;
6
7#[derive(Deserialize, stix_derive::TypedObject)]
8#[typed_object(core)]
9pub struct Identity {
10 #[serde(flatten)]
11 common: CommonProperties,
12 name: String,
13 #[serde(default)]
14 description: Option<String>,
15 #[serde(default)]
16 contact_information: Option<ContactInformation>,
17}
18
19impl Identity {
20 pub fn name(&self) -> &str {
21 &self.name
22 }
23
24 pub fn description(&self) -> Option<&str> {
25 self.description.as_ref().map(|s| s.as_str())
26 }
27
28 pub fn contact_information(&self) -> Option<&ContactInformation> {
29 self.contact_information.as_ref()
30 }
31}
32
33impl AsRef<CommonProperties> for Identity {
34 fn as_ref(&self) -> &CommonProperties {
35 &self.common
36 }
37}
38
39#[derive(Debug, Deserialize, Clone)]
41pub struct ContactInformation(String);
42
43impl fmt::Display for ContactInformation {
44 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45 self.0.fmt(f)
46 }
47}