Open
Conversation
Add BLAKE2b support as a single b2 type with --length for variable
digest size (default 512 bits, max 512 bits). Uses Python's built-in
hashlib.blake2b, so no external dependency is required.
Extract HashSumBase shared base class from BLAKE3. Both BLAKE2 and
BLAKE3 are now thin subclasses with type-specific attributes and an
_is_valid_filename hook. Refactor the b3_* test helpers into shared
_hashsum_* helpers used by both b2 and b3.
Recognized extensions: .b2 (default), .blk (TurboSFV compat), and the
B2SUMS filename. Interoperable with GNU b2sum (two-space format),
verified in the test suite.
Digest-length handling:
- Oversized digests in .b2 files are rejected as malformed chksum
lines (cferror exit 64), not treated as file corruption.
- --length > max_digest_size is validated up-front in make() with a
clean "must be between 8 and 512" error (exit 1), no traceback.
- --length not a multiple of 8 continues to be rejected by the shared
_parse_hash_length validator.
Fixtures: test.b2, B2SUMS, testcrlf.b2, testcrcrlf.b2 (b2sum-style,
generated), test.blk (TurboSFV BLAKE2B-512 reference), and
test.blake2b-{256,384}.b2 covering non-default digest sizes in both
text and binary b2sum formats.
Closes cfv-project#9.
sarsolot
added a commit
to sarsolot/cfv
that referenced
this pull request
Apr 14, 2026
Track upstream with BLAKE3 merged (PR cfv-project#88), acknowledge in-flight BLAKE2 (PR cfv-project#92) and xxhash support. No control changes: Suggests already lists python3-blake3 and python3-xxhash, blake2 uses hashlib and needs no new runtime dependency.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9
Summary
Add BLAKE2 support as a single
b2type, following the same shape asb3(#88).b2type with--lengthfor variable digest size in bits (default 512, max 512)hashlib.blake2b- no external dependency.b2(default),.blk(TurboSFV compat),B2SUMSfilenameb2sum(two-space format, verified in tests)Design decisions
b2sum, which is also blake2b-only. If demand arises, blake2s can be added as a separate type later.--lengthin bits, consistent withb2sum -land the approach adopted forb3. Validated as a multiple of 8 and against blake2b's 8-512 bit range..blkas secondary extension. TurboSFV uses.blkfor BLAKE2B files. Kept as auto detect fallback,.b2is the default for creation.HashSumBase. Extracted from the existing BLAKE3 handler.BLAKE2andBLAKE3are now thin subclasses with type specific attributes and an_is_valid_filenamehook. Test helpers are also shared (_hashsum_roundtrip_test,_hashsum_fixture_test,_hashsum_tool_compat_test, etc.).Digest length handling
.b2file are rejected as a malformed checksum line (cferror, exit 64), not treated as file corruption.--length > max_digest_sizeis validated up-front inmake()with a clean--length for b2 must be between 8 and 512error (exit 1), no traceback.--lengthnot a multiple of 8 is still rejected by the shared_parse_hash_lengthvalidator.Changes
lib/cfv/hash.py—getfileblake2b()lib/cfv/common.py—HashSumBaseextraction,BLAKE2class, up-frontmax_digest_sizevalidation, help text,atremregextest/test.py— shared_hashsum_*test helpers (replace standalone b3 helpers), b2 infmt_info, full coveragetest/testdata/— 7 fixtures:test.b2,test.blk(TurboSFV BLAKE2B-512 reference),B2SUMS,test.blake2b-{256,384}.b2,testcrlf.b2,testcrcrlf.b2README.md,cfv.1,Changelog