#spdx #serde #sbom

serde-spdx

Serde serialization for SPDX files

14 releases (7 breaking)

0.8.4 Jul 13, 2023
0.7.2 Jul 10, 2023

#867 in Encoding

Download history 401/week @ 2024-01-05 345/week @ 2024-01-12 585/week @ 2024-01-19 456/week @ 2024-01-26 616/week @ 2024-02-02 576/week @ 2024-02-09 674/week @ 2024-02-16 650/week @ 2024-02-23 572/week @ 2024-03-01 823/week @ 2024-03-08 511/week @ 2024-03-15 629/week @ 2024-03-22 538/week @ 2024-03-29 879/week @ 2024-04-05 905/week @ 2024-04-12 485/week @ 2024-04-19

2,930 downloads per month
Used in cargo-sbom

MIT license

12KB
80 lines

Workflow Status

serde-spdx

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/.

Usage

For most cases, simply use the root spdx::v_2_3::Spdx struct with [serde] to read and write to and from the struct.

Example

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.

Example

use serde_spdx::spdx::v_2_3::SpdxCreationInfoBuilder;

let creation_info = SpdxCreationInfoBuilder::default()
  .created("created")
  .creators(vec![])
  .build()
  .unwrap();

Internal Implementation Details

The root struct is automatically generated from the parsed SPDX JSON schema, this is done at build time (via the buildscript).

License: MIT

Dependencies

~2–2.8MB
~62K SLoC