Crates.io | serde-spdx |
lib.rs | serde-spdx |
version | 0.9.1 |
source | src |
created_at | 2023-07-04 13:28:45.295291 |
updated_at | 2024-07-09 23:12:37.656899 |
description | Serde serialization for SPDX files |
homepage | https://github.com/psastras/sbom-rs |
repository | https://github.com/psastras/sbom-rs |
max_upload_size | |
id | 907973 |
size | 59,161 |
This crate provides a type safe serde compatible SPDX format. It is intended for use in Rust code which may need to read or write SPDX files.
The latest documentation can be found here.
serde is a popular serialization framework for Rust. More information can be found on the official repository: https://github.com/serde-rs/serde
SDPX is an industry standard format for maintaining a Software Bill of Materials (SBOM). More information can be found on the official website: https://spdx.dev/.
For most cases, simply use the root [spdx::v_2_3::Spdx] struct with [serde] to read and write to and from the struct.
use serde_spdx::spdx::v_2_3::Spdx;
let data = fs::read_to_string("sbom.spdx.json");
let spdx: Spdx = serde_json::from_str(&data).unwrap();
Because many of the [spdx::v_2_3::Spdx] structures contain a lot of optional fields, it is often convenient to use the builder pattern to contstruct these structs. Each structure has a builder with a default.
use serde_spdx::spdx::v_2_3::SpdxCreationInfoBuilder;
let creation_info = SpdxCreationInfoBuilder::default()
.created("created")
.creators(vec![])
.build()
.unwrap();
The root struct is automatically generated from the parsed SPDX JSON schema, this is done at build time (via the buildscript).
License: MIT