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