-
-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
Decoding this example SBOM
<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6"
serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79"
version="1">
</bom>results in a bom object that has no BOMFormat value. When encoding this to a json file it results in the following SBOM
{
"bomFormat": "",
"specVersion": "1.6",
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
"version": 1
}Expected Result:
Based on the input information the BOMFormat should have been set to CycloneDX.
Example coding:
bomFile, err := os.ReadFile("sbom_data/example.xml")
if err != nil {
panic(err)
}
// Decode the BOM
bom := new(cdx.BOM)
decoder := cdx.NewBOMDecoder(bytes.NewReader(bomFile), cdx.BOMFileFormatXML)
if err = decoder.Decode(bom); err != nil {
panic(err)
}
fmt.Printf("Successfully decoded BOM\n")
fmt.Printf("BomFormat %s\n", bom.BOMFormat)
// fmt.Printf("- Generated: %s with %s\n", bom.Metadata.Timestamp, (*bom.Metadata.Tools.Tools)[0].Name)
// fmt.Printf("- Components: %d\n", len(*bom.Components))
// Write SBOM into file
outputBuf := new(bytes.Buffer)
encoder := cdx.NewBOMEncoder(outputBuf, cdx.BOMFileFormatJSON)
encoder.SetPretty(true)
if err = encoder.Encode(bom); err != nil {
panic(err)
}
os.WriteFile("sbom_data/example.json", outputBuf.Bytes(), 0644)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels