github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/internal/file/normalize_hashes.go (about)

     1  package file
     2  
     3  import (
     4  	"crypto"
     5  	"sort"
     6  
     7  	"github.com/scylladb/go-set/uset"
     8  )
     9  
    10  func NormalizeHashes(hashes []crypto.Hash) []crypto.Hash {
    11  	set := uset.New()
    12  	for _, h := range hashes {
    13  		set.Add(uint(h))
    14  	}
    15  	list := set.List()
    16  	sort.Slice(list, func(i, j int) bool {
    17  		return list[i] < list[j]
    18  	})
    19  	result := make([]crypto.Hash, len(list))
    20  	for i, v := range list {
    21  		result[i] = crypto.Hash(v)
    22  	}
    23  	return result
    24  }