github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/binary/package.go (about)

     1  package binary
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/anchore/syft/syft/cpe"
     7  	"github.com/anchore/syft/syft/file"
     8  	"github.com/anchore/syft/syft/pkg"
     9  )
    10  
    11  func newPackage(classifier classifier, location file.Location, matchMetadata map[string]string) *pkg.Package {
    12  	version, ok := matchMetadata["version"]
    13  	if !ok {
    14  		return nil
    15  	}
    16  
    17  	update := matchMetadata["update"]
    18  
    19  	var cpes []cpe.CPE
    20  	for _, c := range classifier.CPEs {
    21  		c.Version = version
    22  		c.Update = update
    23  		cpes = append(cpes, c)
    24  	}
    25  
    26  	p := pkg.Package{
    27  		Name:    classifier.Package,
    28  		Version: version,
    29  		Locations: file.NewLocationSet(
    30  			location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
    31  		),
    32  		Type:    pkg.BinaryPkg,
    33  		CPEs:    cpes,
    34  		FoundBy: catalogerName,
    35  		Metadata: pkg.BinarySignature{
    36  			Matches: []pkg.ClassifierMatch{
    37  				{
    38  					Classifier: classifier.Class,
    39  					Location:   location,
    40  				},
    41  			},
    42  		},
    43  	}
    44  
    45  	if classifier.Type != "" {
    46  		p.Type = classifier.Type
    47  	}
    48  
    49  	if !reflect.DeepEqual(classifier.PURL, emptyPURL) {
    50  		purl := classifier.PURL
    51  		purl.Version = version
    52  		p.PURL = purl.ToString()
    53  	}
    54  
    55  	if classifier.Language != "" {
    56  		p.Language = classifier.Language
    57  	}
    58  
    59  	p.SetID()
    60  
    61  	return &p
    62  }