github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/format/decoders.go (about) 1 package format 2 3 import ( 4 "io" 5 6 "github.com/anchore/syft/syft/format/cyclonedxjson" 7 "github.com/anchore/syft/syft/format/cyclonedxxml" 8 "github.com/anchore/syft/syft/format/spdxjson" 9 "github.com/anchore/syft/syft/format/spdxtagvalue" 10 "github.com/anchore/syft/syft/format/syftjson" 11 "github.com/anchore/syft/syft/sbom" 12 ) 13 14 var staticDecoders sbom.FormatDecoder 15 16 func init() { 17 staticDecoders = NewDecoderCollection(Decoders()...) 18 } 19 20 func Decoders() []sbom.FormatDecoder { 21 return []sbom.FormatDecoder{ 22 syftjson.NewFormatDecoder(), 23 cyclonedxxml.NewFormatDecoder(), 24 cyclonedxjson.NewFormatDecoder(), 25 spdxtagvalue.NewFormatDecoder(), 26 spdxjson.NewFormatDecoder(), 27 } 28 } 29 30 // Identify takes a set of bytes and attempts to identify the format of the SBOM. 31 func Identify(reader io.Reader) (sbom.FormatID, string) { 32 return staticDecoders.Identify(reader) 33 } 34 35 // Decode takes a set of bytes and attempts to decode it into an SBOM. 36 func Decode(reader io.Reader) (*sbom.SBOM, sbom.FormatID, string, error) { 37 return staticDecoders.Decode(reader) 38 }