Skip to content

fix(spdx): support BLAKE2b and Adler-32 in calculate_file_checksum - #918

Open
xgbtxy wants to merge 1 commit into
spdx:mainfrom
xgbtxy:fix/calculate-file-checksum-blake2b-adler32
Open

xgbtxy wants to merge 1 commit into
spdx:mainfrom
xgbtxy:fix/calculate-file-checksum-blake2b-adler32

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Dec 2, 2026

Copy link
Copy Markdown

Description

calculate_file_checksum in src/spdx_tools/spdx/spdx_element_utils.py passes hash_algorithm.name.lower() directly to hashlib.new(...). While SPDX 2.3 defines BLAKE2B_256, BLAKE2B_384, BLAKE2B_512, and ADLER32 in ChecksumAlgorithm (all validated by checksum_validator.py), Python's hashlib.new() rejects "blake2b_256", "blake2b_384", "blake2b_512", and "adler32" with ValueError: unsupported hash type.

This PR adds standard-library support in calculate_file_checksum for:

  • ChecksumAlgorithm.BLAKE2B_256, BLAKE2B_384, BLAKE2B_512 via hashlib.blake2b(digest_size=32|48|64)
  • ChecksumAlgorithm.ADLER32 via streaming zlib.adler32(...) formatted as 8 lowercase hexadecimal digits (08x)

Verification

  • Added multi-chunk parametrized tests in tests/spdx/test_checksum_calculation.py for BLAKE2B_256, BLAKE2B_384, BLAKE2B_512, and ADLER32 (RED -> GREEN).
  • Ran pytest -q (1040 passed, 3 skipped), isort src tests --check, black src tests --check, and flake8 src tests.

Signed-off-by: Yan Chen <yan8925298@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 00:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants