github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/binary/test-fixtures/manager/internal/utils.go (about) 1 package internal 2 3 import ( 4 "crypto/sha256" 5 "fmt" 6 "io" 7 "path/filepath" 8 "strings" 9 ) 10 11 func SplitFilepath(path string) []string { 12 return strings.Split(path, string(filepath.Separator)) 13 } 14 15 func Sha256SumFile(f io.ReadSeeker) (string, error) { 16 _, err := f.Seek(0, io.SeekStart) 17 if err != nil { 18 return "", fmt.Errorf("unable to seek to start of file: %w", err) 19 } 20 hasher := sha256.New() 21 _, err = io.Copy(hasher, f) 22 if err != nil { 23 return "", fmt.Errorf("unable to hash file: %w", err) 24 } 25 26 return fmt.Sprintf("%x", hasher.Sum(nil)), nil 27 } 28 29 func Sha256SumBytes(buf []byte) string { 30 hasher := sha256.New() 31 hasher.Write(buf) 32 return fmt.Sprintf("%x", hasher.Sum(nil)) 33 }