From c6dcc3f76a424a2fde982f288b48e09d1a88f778 Mon Sep 17 00:00:00 2001 From: Javier Parada Date: Thu, 28 Nov 2024 13:19:06 +0100 Subject: [PATCH] add sample entity --- libs/cti/src/cves/domain/entities/cve.rs | 10 +++++ .../cves/domain/entities/cve_description.rs | 37 +++++++++++++++++ libs/cti/src/cves/domain/entities/cve_id.rs | 40 +++++++++++++++++++ .../domain/entities/cve_publication_date.rs | 37 +++++++++++++++++ .../cti/src/cves/domain/entities/cve_state.rs | 37 +++++++++++++++++ libs/cti/src/cves/domain/entities/mod.rs | 5 +++ libs/cti/src/cves/domain/mod.rs | 1 + libs/cti/src/cves/mod.rs | 1 + libs/cti/src/lib.rs | 1 + 9 files changed, 169 insertions(+) create mode 100644 libs/cti/src/cves/domain/entities/cve.rs create mode 100644 libs/cti/src/cves/domain/entities/cve_description.rs create mode 100644 libs/cti/src/cves/domain/entities/cve_id.rs create mode 100644 libs/cti/src/cves/domain/entities/cve_publication_date.rs create mode 100644 libs/cti/src/cves/domain/entities/cve_state.rs create mode 100644 libs/cti/src/cves/domain/entities/mod.rs create mode 100644 libs/cti/src/cves/domain/mod.rs create mode 100644 libs/cti/src/cves/mod.rs diff --git a/libs/cti/src/cves/domain/entities/cve.rs b/libs/cti/src/cves/domain/entities/cve.rs new file mode 100644 index 0000000..332e071 --- /dev/null +++ b/libs/cti/src/cves/domain/entities/cve.rs @@ -0,0 +1,10 @@ +use super::{cve_description::CveDescription, cve_id::CveId, cve_publication_date::CvePublicationDate, cve_state::CveState}; + + +pub struct Cve { + pub id: CveId, + pub state: CveState, + pub date_published: CvePublicationDate, + + pub description: CveDescription, +} \ No newline at end of file diff --git a/libs/cti/src/cves/domain/entities/cve_description.rs b/libs/cti/src/cves/domain/entities/cve_description.rs new file mode 100644 index 0000000..c43b23e --- /dev/null +++ b/libs/cti/src/cves/domain/entities/cve_description.rs @@ -0,0 +1,37 @@ +use crate::shared::domain::errors::DomainError; +use std::hash::{Hash, Hasher}; + +#[derive(Debug)] +pub struct CveDescription { + value: String, +} + +impl CveDescription { + pub fn new(value: String) -> Result { + Ok(Self { value }) + } + + pub fn value(&self) -> String { + self.value.clone() + } +} + +impl Clone for CveDescription { + fn clone(&self) -> Self { + Self::new(self.value.clone()).unwrap() + } +} + +impl PartialEq for CveDescription { + fn eq(&self, other: &Self) -> bool { + self.value() == other.value() + } +} + +impl Eq for CveDescription {} + +impl Hash for CveDescription { + fn hash(&self, state: &mut H) { + self.value.hash(state); + } +} diff --git a/libs/cti/src/cves/domain/entities/cve_id.rs b/libs/cti/src/cves/domain/entities/cve_id.rs new file mode 100644 index 0000000..95bda33 --- /dev/null +++ b/libs/cti/src/cves/domain/entities/cve_id.rs @@ -0,0 +1,40 @@ +use crate::shared::domain::errors::DomainError; +use std::hash::{Hash, Hasher}; + +#[derive(Debug)] +pub struct CveId { + value: String, +} + +impl CveId { + pub fn new(id: String) -> Result { + if id.contains(" ") { + return Err(DomainError::ValueObjectError { value: "CVE id must not contain blank spaces".to_string() }) + } + Ok(Self { value: id }) + } + + pub fn value(&self) -> String { + self.value.clone() + } +} + +impl Clone for CveId { + fn clone(&self) -> Self { + Self::new(self.value.clone()).unwrap() + } +} + +impl PartialEq for CveId { + fn eq(&self, other: &Self) -> bool { + self.value() == other.value() + } +} + +impl Eq for CveId {} + +impl Hash for CveId { + fn hash(&self, state: &mut H) { + self.value.hash(state); + } +} diff --git a/libs/cti/src/cves/domain/entities/cve_publication_date.rs b/libs/cti/src/cves/domain/entities/cve_publication_date.rs new file mode 100644 index 0000000..c62b141 --- /dev/null +++ b/libs/cti/src/cves/domain/entities/cve_publication_date.rs @@ -0,0 +1,37 @@ +use crate::shared::domain::errors::DomainError; +use std::hash::{Hash, Hasher}; + +#[derive(Debug)] +pub struct CvePublicationDate { + value: String, +} + +impl CvePublicationDate { + pub fn new(value: String) -> Result { + Ok(Self { value }) + } + + pub fn value(&self) -> String { + self.value.clone() + } +} + +impl Clone for CvePublicationDate { + fn clone(&self) -> Self { + Self::new(self.value.clone()).unwrap() + } +} + +impl PartialEq for CvePublicationDate { + fn eq(&self, other: &Self) -> bool { + self.value() == other.value() + } +} + +impl Eq for CvePublicationDate {} + +impl Hash for CvePublicationDate { + fn hash(&self, state: &mut H) { + self.value.hash(state); + } +} diff --git a/libs/cti/src/cves/domain/entities/cve_state.rs b/libs/cti/src/cves/domain/entities/cve_state.rs new file mode 100644 index 0000000..182bbb2 --- /dev/null +++ b/libs/cti/src/cves/domain/entities/cve_state.rs @@ -0,0 +1,37 @@ +use crate::shared::domain::errors::DomainError; +use std::hash::{Hash, Hasher}; + +#[derive(Debug)] +pub struct CveState { + value: String, +} + +impl CveState { + pub fn new(value: String) -> Result { + Ok(Self { value }) + } + + pub fn value(&self) -> String { + self.value.clone() + } +} + +impl Clone for CveState { + fn clone(&self) -> Self { + Self::new(self.value.clone()).unwrap() + } +} + +impl PartialEq for CveState { + fn eq(&self, other: &Self) -> bool { + self.value() == other.value() + } +} + +impl Eq for CveState {} + +impl Hash for CveState { + fn hash(&self, state: &mut H) { + self.value.hash(state); + } +} diff --git a/libs/cti/src/cves/domain/entities/mod.rs b/libs/cti/src/cves/domain/entities/mod.rs new file mode 100644 index 0000000..793b7bd --- /dev/null +++ b/libs/cti/src/cves/domain/entities/mod.rs @@ -0,0 +1,5 @@ +pub mod cve; +pub mod cve_description; +pub mod cve_id; +pub mod cve_state; +pub mod cve_publication_date; \ No newline at end of file diff --git a/libs/cti/src/cves/domain/mod.rs b/libs/cti/src/cves/domain/mod.rs new file mode 100644 index 0000000..72a608a --- /dev/null +++ b/libs/cti/src/cves/domain/mod.rs @@ -0,0 +1 @@ +pub mod entities; \ No newline at end of file diff --git a/libs/cti/src/cves/mod.rs b/libs/cti/src/cves/mod.rs new file mode 100644 index 0000000..ae4439e --- /dev/null +++ b/libs/cti/src/cves/mod.rs @@ -0,0 +1 @@ +pub mod domain; \ No newline at end of file diff --git a/libs/cti/src/lib.rs b/libs/cti/src/lib.rs index e69de29..0c6c6d9 100644 --- a/libs/cti/src/lib.rs +++ b/libs/cti/src/lib.rs @@ -0,0 +1 @@ +pub mod cves; \ No newline at end of file