Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/spdx_tools/spdx/validation/checksum_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
ChecksumAlgorithm.BLAKE2B_256: "64",
ChecksumAlgorithm.BLAKE2B_384: "96",
ChecksumAlgorithm.BLAKE2B_512: "128",
ChecksumAlgorithm.BLAKE3: "256,", # at least 256 bits
ChecksumAlgorithm.BLAKE3: "64,", # at least 256 bits
ChecksumAlgorithm.MD2: "32",
ChecksumAlgorithm.MD4: "32",
ChecksumAlgorithm.MD5: "32",
ChecksumAlgorithm.MD6: "0,512", # between 0 and 512 bits
ChecksumAlgorithm.MD6: "1,128", # at most 512 bits
ChecksumAlgorithm.ADLER32: "8",
}

Expand Down Expand Up @@ -58,9 +58,9 @@ def validate_checksum(checksum: Checksum, parent_id: str, spdx_version: str) ->

if not re.match("^[0-9a-f]{" + algorithm_length[algorithm] + "}$", checksum.value):
if algorithm == ChecksumAlgorithm.BLAKE3:
length = "at least 256"
length = "at least 64"
elif algorithm == ChecksumAlgorithm.MD6:
length = "between 0 and 512"
length = "between 1 and 128"
else:
length = algorithm_length[algorithm]
validation_messages.append(
Expand Down
17 changes: 15 additions & 2 deletions tests/spdx/validation/test_checksum_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
ChecksumAlgorithm.MD6,
"af1eec2a1b18886c3f3cc244349d91d8d4c41ce30a517d6ce9d79c8c17bb4b660d7f61beb7018b3924c6b8f96549fa39",
),
Checksum(ChecksumAlgorithm.MD6, "a" * 128),
Checksum(ChecksumAlgorithm.BLAKE3, "aa5b89d0b7005cbddb82b3ed835c4246dddb0a8bda7498736cb873e8646dabf2"),
Checksum(ChecksumAlgorithm.ADLER32, "02ec0130"),
],
)
Expand Down Expand Up @@ -130,7 +132,7 @@ def test_valid_checksum(checksum):
),
(
Checksum(ChecksumAlgorithm.BLAKE3, "af1eec2a1b18886c3f3cc244349d91d8"),
"value of ChecksumAlgorithm.BLAKE3 must consist of at least 256 lowercase hexadecimal digits, but is: af1e"
"value of ChecksumAlgorithm.BLAKE3 must consist of at least 64 lowercase hexadecimal digits, but is: af1e"
"ec2a1b18886c3f3cc244349d91d8 (length: 32 digits)",
),
(
Expand Down Expand Up @@ -158,14 +160,25 @@ def test_valid_checksum(checksum):
"5faa79b63f983341bea41183582b8863d952f6ac3e1cdfe0189967a13006857d3b9985174bf67239874dcec4cbbc983949617"
"9feafed5",
),
"value of ChecksumAlgorithm.MD6 must consist of between 0 and 512 lowercase hexadecimal digits, but is: "
"value of ChecksumAlgorithm.MD6 must consist of between 1 and 128 lowercase hexadecimal digits, but is: "
"a872cac2efd29ed2ad8b5faa79b63f983341bea41183582b8863d952f6ac3e1cdfe0189967a13006857d3b9985174bf67239874dc"
"ec4cbbc9839496179feafeda872cac2efd29ed2ad8b5faa79b63f983341bea41183582b8863d952f6ac3e1cdfe0189967a1300685"
"7d3b9985174bf67239874dcec4cbbc9839496179feafeda872cac2efd29ed2ad8b5faa79b63f983341bea41183582b8863d952f6a"
"c3e1cdfe0189967a13006857d3b9985174bf67239874dcec4cbbc9839496179feafeda872cac2efd29ed2ad8b5faa79b63f983341"
"bea41183582b8863d952f6ac3e1cdfe0189967a13006857d3b9985174bf67239874dcec4cbbc9839496179feafed5 "
"(length: 513 digits)",
),
(
Checksum(ChecksumAlgorithm.MD6, ""),
"value of ChecksumAlgorithm.MD6 must consist of between 1 and 128 lowercase hexadecimal digits, but is: "
" (length: 0 digits)",
),
(
Checksum(ChecksumAlgorithm.MD6, "a" * 129),
"value of ChecksumAlgorithm.MD6 must consist of between 1 and 128 lowercase hexadecimal digits, but is: "
+ "a" * 129
+ " (length: 129 digits)",
),
(
Checksum(ChecksumAlgorithm.ADLER32, "af1eec2a1b18886c3f3cc244349d91d8"),
"value of ChecksumAlgorithm.ADLER32 must consist of 8 lowercase hexadecimal digits, but is: "
Expand Down