cyclonedx-rust-cargo icon indicating copy to clipboard operation
cyclonedx-rust-cargo copied to clipboard

cyclonedx_bom: make Cpe constructable

Open ModestMannfred opened this issue 1 year ago • 2 comments

The current implementation of Cpe in https://github.com/CycloneDX/cyclonedx-rust-cargo/blob/main/cyclonedx-bom/src/models/component.rs does not allow access to the member variable and provides no constructors. Some way to construct Cpes in applications which use the bom library should be provided.

eg.: let cpe = Cpe(cpe_string);

Result:

note: constructor is not visible here due to private fields
   --> /home/scott/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cyclonedx-bom-0.4.3/src/models/component.rs:439:16
    |
439 | pub struct Cpe(pub(crate) String);
    |                ^^^^^^^^^^^^^^^^^ private field

We can implement, if you let us know if you prefer public member variable, a new constructor or conversion from String or &str, etc. Purl, for instance implements both new and FromStr

ModestMannfred avatar Jul 08 '24 10:07 ModestMannfred

Having both new() and FromStr sounds good to me. I'd be happy to merge a PR with this change.

Shnatsel avatar Jul 17 '24 04:07 Shnatsel

Ok, will do. But I need some time because I'm working on something else right now. Thanks!

ModestMannfred avatar Jul 17 '24 06:07 ModestMannfred