#cyclone-dx #codec #decoding #bom #decode #bo-m

cyclonedx-rust

A library for encoding/decoding CycloneDx BoM

1 unstable release

0.1.2 Mar 23, 2021
0.1.1 Mar 18, 2021
0.1.0 Mar 18, 2021

#17 in #bom

Custom license

61KB
1.5K SLoC

cyclonedx-rust

Build Status License

cyclonedx-rust is a simple library to encode/decode CycloneDX BOM

You can encode and decode from any reader type using the methods:

Decoding:

CycloneDX::decode(reader: R, format: CycloneDXFormatType,) -> Result<CycloneDX, CycloneDXDecodeError>

Encoding:

CycloneDX::encode<(writer: W, dx: CycloneDX, format: CycloneDXFormatType,) -> Result<(), CycloneDXEncodeError>

Run cargo docs --open for more detailed documentation


lib.rs:

#CycloneDx-Rust

CycloneDx-Rust is a Crate library for encoding and decoding CycloneDx files in both XML and JSON format to the 1.2 spec

To encode the CycloneDx you cab=n either build up the structure using the provided ::new() methods, passing in the parameters where necessary or make use of the builder pattern. The builder patterns are created at build time so intelli-sense may not be available. Howver, each struct, for example:

use cyclonedx_rust::CycloneDX;

CycloneDX::new(None, None, None, None);

can be built as follows:

use cyclonedx_rust::CycloneDXBuilder;

CycloneDXBuilder::default()
 .metadata(None)
 .components(None)
 .services(None)
 .dependencies(None)
 .build();

Encoding

An example of how to encode a CycloneDX BoM to a file:

use cyclonedx_rust::{CycloneDX, CycloneDXFormatType};
use std::io::BufWriter;
use std::fs::File;

let mut buffer = BufWriter::new(File::create("foo.txt").unwrap());
let cyclone_dx = CycloneDX::new(None, None, None, None);
CycloneDX::encode(&mut buffer, cyclone_dx, CycloneDXFormatType::XML);

Decoding

An example of how to decode a CycloneDX BoM:

use cyclonedx_rust::{CycloneDX, CycloneDXFormatType};
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;

let mut test_folder = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
test_folder.push("resources/test/bom-1.2.xml");
let file = File::open(test_folder);
let mut reader = BufReader::new(file.unwrap());

let result: CycloneDX = CycloneDX::decode(reader, CycloneDXFormatType::XML).unwrap();

Dependencies

~4–10MB
~100K SLoC