Skip to main content

Module integrity

Module integrity 

Source
Expand description

Integrity checking for anything fetched over the network. Compiled always, feature flags or not, so its tests cannot be skipped out of CI. Integrity checking for files fetched over the network.

§Why this module exists

The PaddleOCR backend used to fetch up to ~84 MB of ONNX model weights from a third-party public repository and write them straight to the cache, with no integrity check of any kind. Whoever served those bytes decided what our inference engine executed. For an SDK sold on privacy and on not phoning home, that is the wrong default — and a warning in the README is not a fix, it is a note explaining why the product is wrong.

So fetching is now opt-in and always verified, and this module is the verification. It is compiled unconditionally, without the paddle feature, for one specific reason: tests behind a non-default feature flag do not run in CI, and a security check whose tests never execute is indistinguishable from no check at all. That exact mistake has cost this project three regressions.

Enums§

IntegrityError
Why a downloaded file was rejected.
StreamIntegrityError
Why a streamed verification failed: the read itself, or the digest.

Functions§

sha256_hex
Hex-encoded SHA-256 of bytes.
sha256_hex_of_reader
Hex-encoded SHA-256 of a stream, read 64 KiB at a time.
verify_reader_sha256
Check a stream against an expected hex SHA-256 without holding it in memory.
verify_sha256
Check bytes against an expected hex SHA-256.