Skip to content

Reject variable-length (SHAKE) checksum algorithms instead of crashing#210

Open
arpitjain099 wants to merge 1 commit into
LibraryOfCongress:masterfrom
arpitjain099:chore/shake-checksum-fix
Open

Reject variable-length (SHAKE) checksum algorithms instead of crashing#210
arpitjain099 wants to merge 1 commit into
LibraryOfCongress:masterfrom
arpitjain099:chore/shake-checksum-fix

Conversation

@arpitjain099

Copy link
Copy Markdown

Picking shake_128 or shake_256 as a checksum currently crashes make_bag partway through with "TypeError: shake_128.hexdigest() takes exactly one argument (0 given)", because those SHAKE digests need a length argument that bagit never passes even though they show up in hashlib.algorithms_guaranteed and get offered as CLI flags. This is issue #158.

The fix detects variable-length digests by behavior rather than hardcoding the SHAKE names, so it keeps working if hashlib ever adds more of them. SHAKE is filtered out of CHECKSUM_ALGOS (so it is no longer auto-discovered or shown in --help), make_bag now raises a clear BagError if you ask for one directly, and get_hashers skips them as a safeguard. A normal algorithm like sha3_256 still produces a bag that validates.

Added a few tests for the BagError cases and that SHAKE is no longer advertised. The whole suite passes (117) and black/ruff are happy.

bagit advertised the SHAKE algorithms (shake_128, shake_256) as usable
manifest checksums because they are in hashlib.algorithms_guaranteed, but
their hexdigest() needs a length argument that bagit never supplies, so
make_bag crashed with a TypeError partway through. Detect variable-length
digests by behavior (not by name) and filter them out of CHECKSUM_ALGOS,
raise a clear BagError if one is requested directly, and skip them in
get_hashers as a safeguard. Closes LibraryOfCongress#158.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant