github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/format/internal/spdxutil/helpers/external_refs.go (about)

     1  package helpers
     2  
     3  import (
     4  	"github.com/anchore/syft/syft/pkg"
     5  )
     6  
     7  func ExternalRefs(p pkg.Package) (externalRefs []ExternalRef) {
     8  	externalRefs = make([]ExternalRef, 0)
     9  
    10  	for _, c := range p.CPEs {
    11  		externalRefs = append(externalRefs, ExternalRef{
    12  			ReferenceCategory: SecurityReferenceCategory,
    13  			ReferenceLocator:  c.Attributes.String(),
    14  			ReferenceType:     Cpe23ExternalRefType,
    15  		})
    16  	}
    17  
    18  	if p.PURL != "" {
    19  		externalRefs = append(externalRefs, ExternalRef{
    20  			ReferenceCategory: PackageManagerReferenceCategory,
    21  			ReferenceLocator:  p.PURL,
    22  			ReferenceType:     PurlExternalRefType,
    23  		})
    24  	}
    25  
    26  	return externalRefs
    27  }