mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Correct SPDX-JSON checksum algorithm (#863)
This commit is contained in:
parent
ad322b3314
commit
b2ab4671b9
@ -152,13 +152,19 @@ func toFiles(s sbom.SBOM) []model.File {
|
|||||||
func toFileChecksums(digests []file.Digest) (checksums []model.Checksum) {
|
func toFileChecksums(digests []file.Digest) (checksums []model.Checksum) {
|
||||||
for _, digest := range digests {
|
for _, digest := range digests {
|
||||||
checksums = append(checksums, model.Checksum{
|
checksums = append(checksums, model.Checksum{
|
||||||
Algorithm: digest.Algorithm,
|
Algorithm: toChecksumAlgorithm(digest.Algorithm),
|
||||||
ChecksumValue: digest.Value,
|
ChecksumValue: digest.Value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return checksums
|
return checksums
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toChecksumAlgorithm(algorithm string) string {
|
||||||
|
// basically, we need an uppercase version of our algorithm:
|
||||||
|
// https://github.com/spdx/spdx-spec/blob/development/v2.2.2/schemas/spdx-schema.json#L165
|
||||||
|
return strings.ToUpper(algorithm)
|
||||||
|
}
|
||||||
|
|
||||||
func toFileTypes(metadata *source.FileMetadata) (ty []string) {
|
func toFileTypes(metadata *source.FileMetadata) (ty []string) {
|
||||||
if metadata == nil {
|
if metadata == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -142,7 +142,7 @@ func Test_toFileChecksums(t *testing.T) {
|
|||||||
name: "has digests",
|
name: "has digests",
|
||||||
digests: []file.Digest{
|
digests: []file.Digest{
|
||||||
{
|
{
|
||||||
Algorithm: "sha256",
|
Algorithm: "SHA256",
|
||||||
Value: "deadbeefcafe",
|
Value: "deadbeefcafe",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -152,11 +152,11 @@ func Test_toFileChecksums(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: []model.Checksum{
|
expected: []model.Checksum{
|
||||||
{
|
{
|
||||||
Algorithm: "sha256",
|
Algorithm: "SHA256",
|
||||||
ChecksumValue: "deadbeefcafe",
|
ChecksumValue: "deadbeefcafe",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Algorithm: "md5",
|
Algorithm: "MD5",
|
||||||
ChecksumValue: "meh",
|
ChecksumValue: "meh",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user