account for repoDigests data in power-user json testing

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-03-30 08:46:42 -04:00
parent db35186c7d
commit cd925e5664
5 changed files with 64 additions and 67 deletions
+23 -1
View File
@@ -1,6 +1,9 @@
package cmd
import (
"crypto"
"fmt"
"github.com/anchore/syft/internal/presenter/poweruser"
"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/file"
@@ -80,7 +83,26 @@ func catalogFileDigestTask() (powerUserTask, error) {
return nil, nil
}
digestsCataloger, err := file.NewDigestsCataloger(appConfig.FileMetadata.Digests)
supportedHashAlgorithms := make(map[string]crypto.Hash)
for _, h := range []crypto.Hash{
crypto.MD5,
crypto.SHA1,
crypto.SHA256,
} {
supportedHashAlgorithms[file.DigestAlgorithmName(h)] = h
}
var hashes []crypto.Hash
for _, hashStr := range appConfig.FileMetadata.Digests {
name := file.CleanDigestAlgorithmName(hashStr)
hashObj, ok := supportedHashAlgorithms[name]
if !ok {
return nil, fmt.Errorf("unsupported hash algorithm: %s", hashStr)
}
hashes = append(hashes, hashObj)
}
digestsCataloger, err := file.NewDigestsCataloger(hashes)
if err != nil {
return nil, err
}