- OCaml 99%
- Shell <1%
- Raku <1%
- Python <1%
sbom #
Software bills of materials in CycloneDX 1.6 and SPDX 2.3 for OCaml.
A software bill of materials (SBOM) lists the components a piece of software
is built from, with their versions, licences and digests, so that a customer
or an auditor can check what shipped. The two formats in use are SPDX, an ISO
standard from the Linux Foundation, and CycloneDX, from OWASP. sbom gives
typed OCaml values for both, JSON codecs through jsont, a converter from
SPDX to CycloneDX that reports every fact it cannot carry across, and an SPDX
licence-expression checker for deny-list policies.
Installation #
Install with opam:
$ opam install sbom
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install sbom
Usage #
An SPDX 2.3 document with one package, serialised to JSON:
let doc =
let info =
Spdx.creation_info ~created:"2025-01-01T00:00:00Z"
~creators:["Tool: ocaml-sbom"] ()
in
let pkg =
Spdx.package ~spdx_id:"SPDXRef-pkg"
~name:"my-library" ~version:"1.0.0"
~download_location:"https://example.com/my-library-1.0.0.tar.gz"
~license_declared:"ISC" ()
in
Spdx.document ~name:"my-sbom"
~namespace:"https://example.com/sbom/my-sbom"
~creation_info:info ~packages:[pkg] ()
let json = Spdx.to_string doc
The same library as a CycloneDX 1.6 component, identified by its Package URL:
let bom =
let comp =
Cyclonedx.component ~typ:Library ~name:"my-library" ~version:"1.0.0"
~purl:(Sbom.purl ~typ:"opam" ~name:"my-library" ~version:"1.0.0" ())
~licenses:[Sbom.license_id "ISC"] ()
in
Cyclonedx.bom [comp]
let json = Cyclonedx.to_string bom
API #
The package has six libraries and one command.
sbom(moduleSbom) holds the types both formats share: hash algorithms and digests, licence references, Package URLs and the parse error.sbom.spdx(moduleSpdx) models SPDX 2.3 documents: creation information, packages, files, checksums, external references and relationships.sbom.cyclonedx(moduleCyclonedx) models CycloneDX 1.6 BOMs: components, including files, data and cryptographic assets, metadata and the dependency graph.sbom.convert(moduleSbom_convert) converts the SPDX packages a caller selects, and the dependencies between them, to CycloneDX. It returns a diagnostic for every relationship or checksum that CycloneDX cannot carry exactly, and refuses duplicate or dangling identifiers.sbom.license(moduleSbom_license) parses SPDX licence expressions and checks them, or every package of a document, against a deny list.sbom.validate(moduleSbom_validate) checks a CycloneDX 1.6 JSON document against the 1.6.1 schema bundled fromspec/cyclonedx-1.6, then checks that its bom-refs are unique and that every reference from its dependencies and compositions names one. Thesbom-validate FILEcommand runs both checks and prints each error with its JSON Pointer.
Sbom_license.check_expression treats an expression it cannot parse as
compliant. Parse with Sbom_license.parse first when a malformed expression
must be refused.
References #
License #
ISC. See LICENSE.md.