Skip to main content

Module sha1

Module sha1 

Source
Expand description

SHA-1 digest helpers. Exposed because the operator-side wire layer (kevy-rt’s SCRIPT LOAD / EVALSHA codec) needs to convert between the 20-byte digest used as a cache key and the 40-char ASCII hex Redis uses on the wire. Hand-rolled SHA-1 (RFC 3174 / FIPS 180-1).

Used by the SCRIPT LOAD / EVALSHA cache key and the redis.sha1hex host fn. Kevy’s L2 lockdown forbids crates.io third-party deps; SHA-1 is short enough to write once and lint against well-known test vectors.

§NOT a security primitive

SHA-1 is broken for collision resistance (SHAttered, 2017+). That doesn’t matter here — kevy uses it as a content-addressed cache key the same way Redis does, where collisions would only cause cross-script cache hits (which never produces a security issue) and Redis itself uses SHA-1 for the same reason.

If kevy ever needs SHA-1 / SHA-256 for an actual security-bearing purpose, that’s a separate kevy-crypto stone, not here.

Functions§

hex
Format a 20-byte SHA-1 digest as 40 lowercase ASCII hex chars.
parse_hex
Parse a 40-character ASCII hex string into a SHA-1 digest. Returns None on malformed input (wrong length or non-hex chars).
sha1
Compute the SHA-1 of data. Returns the 20-byte digest.