github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/cyclonedxjson/encoder.go (about) 1 package cyclonedxjson 2 3 import ( 4 "github.com/CycloneDX/cyclonedx-go" 5 6 "github.com/anchore/syft/syft/sbom" 7 "github.com/lineaje-labs/syft/syft/format/internal/cyclonedxutil" 8 ) 9 10 const ID = cyclonedxutil.JSONFormatID 11 12 func SupportedVersions() []string { 13 return cyclonedxutil.SupportedVersions(ID) 14 } 15 16 type EncoderConfig struct { 17 Version string 18 Pretty bool // don't include spaces and newlines; same as jq -c 19 } 20 21 type encoder struct { 22 cfg EncoderConfig 23 cyclonedxutil.Encoder 24 } 25 26 func NewFormatEncoderWithConfig(cfg EncoderConfig) (sbom.FormatEncoder, error) { 27 enc, err := cyclonedxutil.NewEncoder(cfg.Version, cyclonedx.BOMFileFormatJSON, cfg.Pretty) 28 if err != nil { 29 return nil, err 30 } 31 return encoder{ 32 cfg: cfg, 33 Encoder: enc, 34 }, nil 35 } 36 37 func DefaultEncoderConfig() EncoderConfig { 38 return EncoderConfig{ 39 Version: cyclonedxutil.DefaultVersion, 40 Pretty: false, 41 } 42 } 43 44 func (e encoder) ID() sbom.FormatID { 45 return ID 46 } 47 48 func (e encoder) Aliases() []string { 49 return []string{} 50 } 51 52 func (e encoder) Version() string { 53 return e.cfg.Version 54 }