Skip to content

Commit

Permalink
Correct SPDX-JSON checksum algorithm (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow authored Mar 3, 2022
1 parent ad322b3 commit b2ab467
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion internal/formats/spdx22json/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,19 @@ func toFiles(s sbom.SBOM) []model.File {
func toFileChecksums(digests []file.Digest) (checksums []model.Checksum) {
for _, digest := range digests {
checksums = append(checksums, model.Checksum{
Algorithm: digest.Algorithm,
Algorithm: toChecksumAlgorithm(digest.Algorithm),
ChecksumValue: digest.Value,
})
}
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) {
if metadata == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/formats/spdx22json/to_format_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func Test_toFileChecksums(t *testing.T) {
name: "has digests",
digests: []file.Digest{
{
Algorithm: "sha256",
Algorithm: "SHA256",
Value: "deadbeefcafe",
},
{
Expand All @@ -152,11 +152,11 @@ func Test_toFileChecksums(t *testing.T) {
},
expected: []model.Checksum{
{
Algorithm: "sha256",
Algorithm: "SHA256",
ChecksumValue: "deadbeefcafe",
},
{
Algorithm: "md5",
Algorithm: "MD5",
ChecksumValue: "meh",
},
},
Expand Down

0 comments on commit b2ab467

Please sign in to comment.