feat(checksum): expose Crc32/Adler32 as public API behind a checksum feature - #127
Merged
Conversation
…` feature The crate already carries a slice-by-8 IEEE CRC-32 and an RFC 1950 Adler-32 for the zlib/gzip trailers and rar3's filter recognition, but `mod checksum` was private, so callers could not reach them. That gap has a cost. These codecs decode *data streams*, not container framing, so a caller that parses the container itself — a ZIP local header, a PNG IDAT chunk, a RAR file header — has to verify the checksum fields on its own, and had to pull in a second crate to do it. `src/xz/mod.rs` hit the same wall from inside the crate and keeps a duplicate byte-at-a-time CRC-32 with a comment saying so: "the wider crate has a `checksum::Crc32` but it is feature-gated to `gzip`; in an `xz`-only build we'd lose access". Adds a `checksum` feature that promotes the module to `pub`. Visibility is the only thing it changes: when a codec needs the module it is compiled either way, and each type keeps its existing per-codec gate so a `zlib`-only build still doesn't carry the CRC table (or vice versa). The feature costs no `alloc` — both are plain `u32` state machines that work in `no_std`. `Crc32::reset` was gated to `gzip` alone; it is now also available under the feature so a caller can reuse one instance across members. Verified from a downstream crate that `compcol::checksum` is unreachable without the feature and reachable with it, and built across zlib-only, gzip-only, rar3-only, checksum-only (no default features, no alloc), the combinations, and --all-features.
MagicalTux
force-pushed
the
feat/export-checksum
branch
from
September 4, 2026 03:27
00890bb to
ed626b6
Compare
Merged
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.
The crate already carries a slice-by-8 IEEE CRC-32 and an RFC 1950 Adler-32 for the zlib/gzip trailers and rar3's filter recognition, but
mod checksumwas private, so callers could not reach them.That gap has a cost. These codecs decode data streams, not container framing, so a caller that parses the container itself — a ZIP local header, a PNG
IDATchunk, a RAR file header — has to verify the checksum fields on its own, and had to pull in a second crate to do it.The crate hit the same wall internally:
src/xz/mod.rskeeps a duplicate byte-at-a-time CRC-32 with a comment explaining why —What this changes
A
checksumfeature that promotes the module topub. Visibility is the only thing it changes:zlib-only build still doesn't carry the CRC table, and agzip-only build still doesn't carry Adler-32;alloc— both are plainu32state machines, usable inno_std.Crc32::resetwas gated togzipalone; it is now also available under the feature, so a caller can reuse one instance across members. The public methods gained docs and the module a doctest.Verification
Confirmed from a scratch downstream crate that
compcol::checksumis a compile error without the feature and works with it (Crc32over"123456789"→0xCBF43926, the CRC catalogue check value).Built clean across:
checksumalone (--no-default-features, no alloc),zlib-only,gzip-only,rar3-only,zlib+checksum,rar3+checksum,xz-only, and--all-features.cargo test --all-features: 1767 pass, 0 fail.fmtclean; docs build clean with-D warnings.Deliberately not included: switching
xz(or bzip2, which uses a different polynomial) over to the shared implementation. That is a behaviour-neutral but perf-relevant refactor — xz's copy is byte-at-a-time, the shared one is slice-by-8 — and belongs in its own change.