Documentation
¶
Index ¶
Constants ¶
const ( SBOM_CYCLONEDX = "CycloneDX" SBOM_SPDX = "SPDX" )
Variables ¶
This section is empty.
Functions ¶
func SetDebugLogging ¶
func SetDebugLogging(enabled bool)
SetDebugLogging enables or disables package debug logs.
Types ¶
type ValidationResult ¶
type ValidationResult struct {
IsValid bool `json:"isValid"`
SBOMType string `json:"sbomType,omitempty"`
SBOMVersion string `json:"sbomVersion,omitempty"`
ValidationErrors []string `json:"validationErrors,omitempty"`
SchemaUsed string `json:"schemaUsed,omitempty"`
DetectedFormat string `json:"detectedFormat,omitempty"`
}
ValidationResult represents the outcome of validating a Software Bill of Materials (SBOM).
It provides detailed information about the validation process, including:
- Whether the SBOM is valid (`IsValid`).
- The detected SBOM type (e.g., CycloneDX, SPDX).
- The SBOM schema or specification version.
- A list of any validation errors encountered.
- The schema file or source used during validation.
- The detected input format (e.g., JSON, XML, etc.).
This struct is returned by `ValidateSBOMData` and can be serialized to JSON for use in CLI tools, APIs, or automated pipelines.
func ValidateSBOMData ¶
func ValidateSBOMData(sbomContent []byte) (*ValidationResult, error)
ValidateSBOMData is the main function to validate SBOM data using this library.
This function serves as a wrapper around multiple internal functions, making it the recommended entry point for validating SBOMs. It performs the following steps: 1. Detects whether the SBOM is in JSON format. 2. Determines the SBOM type (CycloneDX, SPDX, etc.). 3. Extracts the schema version from the SBOM data. 4. Loads the corresponding schema for validation. 5. Validates the SBOM against the schema and returns the validation result.
Parameters:
- sbomContent: A byte slice containing the SBOM data.
Returns:
- bool: `true` if the SBOM is valid, `false` otherwise.
- []string: A list of validation error messages if the SBOM is invalid (nil if valid).
- error: An error if the function encounters issues during validation.
Errors:
- Returns an error if the SBOM format is not JSON.
- Returns an error if SBOM type detection fails.
- Returns an error if the SBOM type is not CycloneDX (currently the only supported format).
- Returns an error if extracting the SBOM version fails.
- Returns an error if loading the schema fails.
Note:
- This function abstracts multiple lower-level functions, such as `DetectSBOMType`, `ExtractVersion`, `LoadSchema`, and `ValidateSBOM`. Instead of calling those individually, use `ValidateSBOMData` for a streamlined validation process.
Example usage:
isValid, errors, err := ValidateSBOMData(sbomBytes)
if err != nil {
log.Fatalf("SBOM validation failed: %v", err)
}
if isValid {
fmt.Println("SBOM is valid!")
} else {
fmt.Println("SBOM validation errors:", errors)
}