-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cb700c
commit 5202a6b
Showing
10 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::shared::domain::errors::DomainError; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[derive(Debug)] | ||
pub struct BreachId { | ||
value: String, | ||
} | ||
|
||
impl BreachId { | ||
pub fn new(id: &String) -> Result<Self, DomainError> { | ||
if id.contains(" ") { | ||
return Err(DomainError::ValueObjectError { | ||
value: "CVE id must not contain blank spaces".to_string(), | ||
}); | ||
} | ||
Ok(Self { value: id.clone() }) | ||
} | ||
|
||
pub fn from_optional(id: &Option<String>) -> Result<Self, DomainError> { | ||
if id.is_none() { | ||
return Err(DomainError::ValueObjectError { | ||
value: "CVE id must not be empty".to_string(), | ||
}); | ||
} | ||
let id = id.as_ref().unwrap(); | ||
Self::new(&id) | ||
} | ||
|
||
pub fn value(&self) -> String { | ||
self.value.clone() | ||
} | ||
|
||
pub fn rvalue(&self) -> &String { | ||
&self.value | ||
} | ||
} | ||
|
||
impl Clone for BreachId { | ||
fn clone(&self) -> Self { | ||
Self::new(&self.value).unwrap() | ||
} | ||
} | ||
|
||
impl PartialEq for BreachId { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.value() == other.value() | ||
} | ||
} | ||
|
||
impl Eq for BreachId {} | ||
|
||
impl Hash for BreachId { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.value.hash(state); | ||
} | ||
} | ||
|
||
impl std::fmt::Display for BreachId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::shared::domain::errors::DomainError; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[derive(Debug)] | ||
pub struct BreachProduct { | ||
value: String, | ||
} | ||
|
||
impl BreachProduct { | ||
pub fn new(value: &String) -> Result<Self, DomainError> { | ||
Ok(Self { | ||
value: value.clone(), | ||
}) | ||
} | ||
|
||
pub fn from_optional(value: &Option<String>) -> Result<Self, DomainError> { | ||
if value.is_none() { | ||
return Err(DomainError::ValueObjectError { | ||
value: "CVE state must not be null".to_string(), | ||
}); | ||
} | ||
let value = value.as_ref().unwrap(); | ||
Self::new(&value) | ||
} | ||
|
||
pub fn value(&self) -> String { | ||
self.value.clone() | ||
} | ||
|
||
pub fn ref_value(&self) -> &String { | ||
&self.value | ||
} | ||
} | ||
|
||
impl Clone for BreachProduct { | ||
fn clone(&self) -> Self { | ||
Self::new(&self.value).unwrap() | ||
} | ||
} | ||
|
||
impl PartialEq for BreachProduct { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.value() == other.value() | ||
} | ||
} | ||
|
||
impl Eq for BreachProduct {} | ||
|
||
impl Hash for BreachProduct { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.value.hash(state); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
libs/cti/src/breaches/domain/entities/breach_product_type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::shared::domain::errors::DomainError; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[derive(Debug)] | ||
pub struct BreachProductType { | ||
value: String, | ||
} | ||
|
||
impl BreachProductType { | ||
pub fn new(value: &String) -> Result<Self, DomainError> { | ||
Ok(Self { | ||
value: value.clone(), | ||
}) | ||
} | ||
|
||
pub fn from_optional(value: &Option<String>) -> Result<Self, DomainError> { | ||
if value.is_none() { | ||
return Err(DomainError::ValueObjectError { | ||
value: "CVE state must not be null".to_string(), | ||
}); | ||
} | ||
let value = value.as_ref().unwrap(); | ||
Self::new(&value) | ||
} | ||
|
||
pub fn value(&self) -> String { | ||
self.value.clone() | ||
} | ||
|
||
pub fn ref_value(&self) -> &String { | ||
&self.value | ||
} | ||
} | ||
|
||
impl Clone for BreachProductType { | ||
fn clone(&self) -> Self { | ||
Self::new(&self.value).unwrap() | ||
} | ||
} | ||
|
||
impl PartialEq for BreachProductType { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.value() == other.value() | ||
} | ||
} | ||
|
||
impl Eq for BreachProductType {} | ||
|
||
impl Hash for BreachProductType { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.value.hash(state); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
libs/cti/src/breaches/domain/entities/breach_product_version.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::shared::domain::errors::DomainError; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[derive(Debug)] | ||
pub struct BreachProductVersion { | ||
value: String, | ||
} | ||
|
||
impl BreachProductVersion { | ||
pub fn new(value: &String) -> Result<Self, DomainError> { | ||
Ok(Self { | ||
value: value.clone(), | ||
}) | ||
} | ||
|
||
pub fn from_optional(value: &Option<String>) -> Result<Self, DomainError> { | ||
if value.is_none() { | ||
return Err(DomainError::ValueObjectError { | ||
value: "CVE state must not be null".to_string(), | ||
}); | ||
} | ||
let value = value.as_ref().unwrap(); | ||
Self::new(&value) | ||
} | ||
|
||
pub fn value(&self) -> String { | ||
self.value.clone() | ||
} | ||
|
||
pub fn ref_value(&self) -> &String { | ||
&self.value | ||
} | ||
} | ||
|
||
impl Clone for BreachProductVersion { | ||
fn clone(&self) -> Self { | ||
Self::new(&self.value).unwrap() | ||
} | ||
} | ||
|
||
impl PartialEq for BreachProductVersion { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.value() == other.value() | ||
} | ||
} | ||
|
||
impl Eq for BreachProductVersion {} | ||
|
||
impl Hash for BreachProductVersion { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.value.hash(state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::shared::domain::errors::DomainError; | ||
use std::hash::{Hash, Hasher}; | ||
|
||
#[derive(Debug)] | ||
pub struct BreachVendor { | ||
value: String, | ||
} | ||
|
||
impl BreachVendor { | ||
pub fn new(value: &String) -> Result<Self, DomainError> { | ||
Ok(Self { | ||
value: value.clone(), | ||
}) | ||
} | ||
|
||
pub fn from_optional(value: &Option<String>) -> Result<Self, DomainError> { | ||
if value.is_none() { | ||
return Err(DomainError::ValueObjectError { | ||
value: "CVE state must not be null".to_string(), | ||
}); | ||
} | ||
let value = value.as_ref().unwrap(); | ||
Self::new(&value) | ||
} | ||
|
||
pub fn value(&self) -> String { | ||
self.value.clone() | ||
} | ||
|
||
pub fn ref_value(&self) -> &String { | ||
&self.value | ||
} | ||
} | ||
|
||
impl Clone for BreachVendor { | ||
fn clone(&self) -> Self { | ||
Self::new(&self.value).unwrap() | ||
} | ||
} | ||
|
||
impl PartialEq for BreachVendor { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.value() == other.value() | ||
} | ||
} | ||
|
||
impl Eq for BreachVendor {} | ||
|
||
impl Hash for BreachVendor { | ||
fn hash<H: Hasher>(&self, state: &mut H) { | ||
self.value.hash(state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod breach_id; | ||
pub mod breach_product; | ||
pub mod breach_product_type; | ||
pub mod breach_product_version; | ||
pub mod breach_vendor; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod entities; | ||
pub mod repositories; | ||
pub mod events; |
Empty file.