Skip to content

Commit

Permalink
Merge pull request #758 from justahero/fix-cpe-from-str
Browse files Browse the repository at this point in the history
Change visibility of model types
  • Loading branch information
Shnatsel authored Aug 6, 2024
2 parents 04fe7cc + 76f6fb5 commit e26d8db
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 153 deletions.
12 changes: 6 additions & 6 deletions cyclonedx-bom/src/models/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ impl Validate for Annotations {

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Annotation {
pub(crate) bom_ref: Option<String>,
pub(crate) subjects: Vec<String>,
pub(crate) annotator: Annotator,
pub(crate) timestamp: DateTime,
pub(crate) text: String,
pub(crate) signature: Option<Signature>,
pub bom_ref: Option<String>,
pub subjects: Vec<String>,
pub annotator: Annotator,
pub timestamp: DateTime,
pub text: String,
pub signature: Option<Signature>,
}

impl Validate for Annotation {
Expand Down
12 changes: 6 additions & 6 deletions cyclonedx-bom/src/models/attached_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use super::bom::SpecVersion;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AttachedText {
pub(crate) content_type: Option<NormalizedString>,
pub(crate) encoding: Option<Encoding>,
pub(crate) content: String,
pub content_type: Option<NormalizedString>,
pub encoding: Option<Encoding>,
pub content: String,
}

impl AttachedText {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Validate for AttachedText {
}

/// Function to check [`Encoding`].
pub(crate) fn validate_encoding(encoding: &Encoding) -> Result<(), ValidationError> {
pub fn validate_encoding(encoding: &Encoding) -> Result<(), ValidationError> {
if matches!(encoding, Encoding::UnknownEncoding(_)) {
return Err(ValidationError::new("Unknown encoding"));
}
Expand All @@ -83,15 +83,15 @@ pub(crate) fn validate_encoding(encoding: &Encoding) -> Result<(), ValidationErr

#[derive(Clone, Debug, PartialEq, Eq, strum::Display, Hash)]
#[strum(serialize_all = "kebab-case")]
pub(crate) enum Encoding {
pub enum Encoding {
Base64,
#[doc(hidden)]
#[strum(default)]
UnknownEncoding(String),
}

impl Encoding {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"base64" => Self::Base64,
unknown => Self::UnknownEncoding(unknown.to_string()),
Expand Down
6 changes: 3 additions & 3 deletions cyclonedx-bom/src/models/bom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl FromStr for SpecVersion {
}
}

pub(crate) fn validate_bom_ref(
pub fn validate_bom_ref(
_bom_ref: &BomReference,
version: SpecVersion,
) -> Result<(), ValidationError> {
Expand All @@ -91,7 +91,7 @@ pub(crate) fn validate_bom_ref(

/// A reference to a Bom element
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct BomReference(pub(crate) String);
pub struct BomReference(pub String);

impl BomReference {
pub fn new<T>(input: T) -> Self
Expand Down Expand Up @@ -576,7 +576,7 @@ fn validate_vulnerabilities_bom_refs(
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UrnUuid(pub(crate) String);
pub struct UrnUuid(pub String);

impl UrnUuid {
pub fn new(value: String) -> Result<Self, UrnUuidError> {
Expand Down
4 changes: 2 additions & 2 deletions cyclonedx-bom/src/models/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub enum IssueClassification {
}

impl IssueClassification {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"defect" => Self::Defect,
"enhancement" => Self::Enhancement,
Expand Down Expand Up @@ -216,7 +216,7 @@ pub enum PatchClassification {
}

impl PatchClassification {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"unofficial" => Self::Unofficial,
"monkey" => Self::Monkey,
Expand Down
28 changes: 23 additions & 5 deletions cyclonedx-bom/src/models/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub enum Classification {
}

impl Classification {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"application" => Self::Application,
"framework" => Self::Framework,
Expand Down Expand Up @@ -256,7 +256,7 @@ pub enum Scope {
}

impl Scope {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"required" => Self::Required,
"optional" => Self::Optional,
Expand All @@ -281,7 +281,7 @@ pub fn validate_mime_type(mime_type: &MimeType) -> Result<(), ValidationError> {
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct MimeType(pub(crate) String);
pub struct MimeType(pub String);

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Swid {
Expand Down Expand Up @@ -322,6 +322,24 @@ pub fn validate_cpe(cpe: &Cpe) -> Result<(), ValidationError> {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Cpe(pub(crate) String);

impl Cpe {
pub fn new(inner: &str) -> Self {
Self(inner.to_string())
}
}

impl From<String> for Cpe {
fn from(value: String) -> Self {
Self(value)
}
}

impl AsRef<String> for Cpe {
fn as_ref(&self) -> &String {
&self.0
}
}

impl AsRef<str> for Cpe {
fn as_ref(&self) -> &str {
&self.0
Expand Down Expand Up @@ -513,7 +531,7 @@ pub enum IdentityField {
}

impl IdentityField {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"group" => Self::Group,
"name" => Self::Name,
Expand Down Expand Up @@ -593,7 +611,7 @@ pub fn validate_copyright(_copyright: &Copyright) -> Result<(), ValidationError>
pub struct Copyright(pub String);

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CopyrightTexts(pub(crate) Vec<Copyright>);
pub struct CopyrightTexts(pub Vec<Copyright>);

impl Validate for CopyrightTexts {
fn validate_version(&self, _version: SpecVersion) -> ValidationResult {
Expand Down
2 changes: 1 addition & 1 deletion cyclonedx-bom/src/models/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub enum AggregateType {
}

impl AggregateType {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"complete" => Self::Complete,
"incomplete" => Self::Incomplete,
Expand Down
4 changes: 2 additions & 2 deletions cyclonedx-bom/src/models/external_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub enum ExternalReferenceType {
}

impl ExternalReferenceType {
pub(crate) fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
pub fn new_unchecked<A: AsRef<str>>(value: A) -> Self {
match value.as_ref() {
"vcs" => Self::Vcs,
"issue-tracker" => Self::IssueTracker,
Expand Down Expand Up @@ -226,7 +226,7 @@ impl std::fmt::Display for Uri {
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct BomLink(pub(crate) String);
pub struct BomLink(pub String);

fn validate_bom_link(bom_link: &BomLink, version: SpecVersion) -> Result<(), ValidationError> {
if version < SpecVersion::V1_5 {
Expand Down
10 changes: 5 additions & 5 deletions cyclonedx-bom/src/models/formulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use super::{bom::BomReference, component::Components, property::Properties, serv

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Formula {
pub(crate) bom_ref: Option<BomReference>,
pub(crate) components: Option<Components>,
pub(crate) services: Option<Services>,
pub(crate) workflows: Option<Vec<Workflow>>,
pub(crate) properties: Option<Properties>,
pub bom_ref: Option<BomReference>,
pub components: Option<Components>,
pub services: Option<Services>,
pub workflows: Option<Vec<Workflow>>,
pub properties: Option<Properties>,
}

impl Validate for Formula {
Expand Down
20 changes: 10 additions & 10 deletions cyclonedx-bom/src/models/formulation/workflow/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::{
use super::{resource_reference::ResourceReference, EnvironmentVar};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct Input {
pub(crate) required: RequiredInputField,
pub(crate) source: Option<ResourceReference>,
pub(crate) target: Option<ResourceReference>,
pub(crate) properties: Option<Properties>,
pub struct Input {
pub required: RequiredInputField,
pub source: Option<ResourceReference>,
pub target: Option<ResourceReference>,
pub properties: Option<Properties>,
}

impl Validate for Input {
Expand Down Expand Up @@ -39,16 +39,16 @@ impl Validate for Input {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) enum RequiredInputField {
pub enum RequiredInputField {
Resource(ResourceReference),
Parameters(Vec<Parameter>),
EnvironmentVars(Vec<EnvironmentVar>),
Data(Attachment),
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct Parameter {
pub(crate) name: Option<String>,
pub(crate) value: Option<String>,
pub(crate) data_type: Option<String>,
pub struct Parameter {
pub name: Option<String>,
pub value: Option<String>,
pub data_type: Option<String>,
}
74 changes: 37 additions & 37 deletions cyclonedx-bom/src/models/formulation/workflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ use self::{
};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct Workflow {
pub(crate) bom_ref: BomReference,
pub(crate) uid: String,
pub(crate) name: Option<String>,
pub(crate) description: Option<String>,
pub(crate) resource_references: Option<Vec<ResourceReference>>,
pub(crate) tasks: Option<Vec<Task>>,
pub(crate) task_dependencies: Option<Vec<Dependency>>,
pub(crate) task_types: Vec<TaskType>,
pub(crate) trigger: Option<Trigger>,
pub(crate) steps: Option<Vec<Step>>,
pub(crate) inputs: Option<Vec<Input>>,
pub(crate) outputs: Option<Vec<Output>>,
pub(crate) time_start: Option<DateTime>,
pub(crate) time_end: Option<DateTime>,
pub(crate) workspaces: Option<Vec<Workspace>>,
pub(crate) runtime_topology: Option<Vec<Dependency>>,
pub(crate) properties: Option<Properties>,
pub struct Workflow {
pub bom_ref: BomReference,
pub uid: String,
pub name: Option<String>,
pub description: Option<String>,
pub resource_references: Option<Vec<ResourceReference>>,
pub tasks: Option<Vec<Task>>,
pub task_dependencies: Option<Vec<Dependency>>,
pub task_types: Vec<TaskType>,
pub trigger: Option<Trigger>,
pub steps: Option<Vec<Step>>,
pub inputs: Option<Vec<Input>>,
pub outputs: Option<Vec<Output>>,
pub time_start: Option<DateTime>,
pub time_end: Option<DateTime>,
pub workspaces: Option<Vec<Workspace>>,
pub runtime_topology: Option<Vec<Dependency>>,
pub properties: Option<Properties>,
}

impl Validate for Workflow {
Expand Down Expand Up @@ -81,22 +81,22 @@ impl Validate for Workflow {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct Task {
pub(crate) bom_ref: BomReference,
pub(crate) uid: String,
pub(crate) name: Option<String>,
pub(crate) description: Option<String>,
pub(crate) resource_references: Option<Vec<ResourceReference>>,
pub(crate) task_types: Vec<TaskType>,
pub(crate) trigger: Option<Trigger>,
pub(crate) steps: Option<Vec<Step>>,
pub(crate) inputs: Option<Vec<Input>>,
pub(crate) outputs: Option<Vec<Output>>,
pub(crate) time_start: Option<DateTime>,
pub(crate) time_end: Option<DateTime>,
pub(crate) workspaces: Option<Vec<Workspace>>,
pub(crate) runtime_topology: Option<Vec<Dependency>>,
pub(crate) properties: Option<Properties>,
pub struct Task {
pub bom_ref: BomReference,
pub uid: String,
pub name: Option<String>,
pub description: Option<String>,
pub resource_references: Option<Vec<ResourceReference>>,
pub task_types: Vec<TaskType>,
pub trigger: Option<Trigger>,
pub steps: Option<Vec<Step>>,
pub inputs: Option<Vec<Input>>,
pub outputs: Option<Vec<Output>>,
pub time_start: Option<DateTime>,
pub time_end: Option<DateTime>,
pub workspaces: Option<Vec<Workspace>>,
pub runtime_topology: Option<Vec<Dependency>>,
pub properties: Option<Properties>,
}

impl Validate for Task {
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Validate for Task {

#[derive(Debug, Clone, PartialEq, Eq, Hash, strum::Display)]
#[strum(serialize_all = "kebab-case")]
pub(crate) enum TaskType {
pub enum TaskType {
Copy,
Clone,
Lint,
Expand All @@ -155,7 +155,7 @@ pub(crate) enum TaskType {
}

impl TaskType {
pub(crate) fn new_unchecked<S: AsRef<str>>(s: S) -> Self {
pub fn new_unchecked<S: AsRef<str>>(s: S) -> Self {
match s.as_ref() {
"copy" => Self::Copy,
"clone" => Self::Clone,
Expand Down Expand Up @@ -188,7 +188,7 @@ impl Validate for TaskType {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) enum EnvironmentVar {
pub enum EnvironmentVar {
Property { name: String, value: String },
Value(String),
}
Loading

0 comments on commit e26d8db

Please sign in to comment.