syft/syft/pkg/merge_cpes.go

26 lines
486 B
Go

package pkg
import (
"sort"
)
func mergeCPEs(a, b []CPE) (result []CPE) {
aCPEs := make(map[string]CPE)
// keep all CPEs from a and create a quick string-based lookup
for _, aCPE := range a {
aCPEs[aCPE.BindToFmtString()] = aCPE
result = append(result, aCPE)
}
// keep all unique CPEs from b
for _, bCPE := range b {
if _, exists := aCPEs[bCPE.BindToFmtString()]; !exists {
result = append(result, bCPE)
}
}
sort.Sort(CPEBySpecificity(result))
return result
}