Skip to content

l0.DependencyControl.hash

hash = require "l0.DependencyControl.hash"
local hash = require("l0.DependencyControl.hash")

Functions

getDigest

Hash.getDigest hashType, data
Hash.getDigest(hashType, data)

Computes the digest of a string under the given algorithm. Accepts arbitrary binary data: Lua strings are byte-safe, so any byte sequence (e.g. a file read in binary mode) hashes correctly. A raw FFI buffer must be converted with ffi.string(buf, len) first. Suitable for file integrity verification; not for security-sensitive use.

param type description
hashType HashType The hash algorithm to use.
data string The input bytes (may be binary).

Returns:

  • digest string? — A lowercase hex digest, or nil on invalid input.
  • err string?

verify

Hash.verify hashType, data, expected
Hash.verify(hashType, data, expected)

Checks whether a string hashes to an expected digest under the given algorithm.

param type description
hashType HashType The hash algorithm to use.
data string The input bytes to hash.
expected string The expected hex digest (compared case-insensitively).

Returns:

  • match boolean? — True on match, false on mismatch, or nil on error.
  • err string? — The mismatch detail or error message.

getObjectHash

Hash.getObjectHash value
Hash.getObjectHash(value)

Produces a deterministic SHA-1 hash of a (possibly nested) Lua value. Table keys are sorted before hashing, so field ordering never affects the result; pass an object pruned to just the fields you care about to obtain a stable content signature that ignores irrelevant differences. Useful for cheaply detecting whether semantic content changed.

param type description
value any The value to hash.

Returns:

  • hash string — A 40-character lowercase SHA-1 hex digest.

Fields

field type description
sha1Backend string

Enums

HashType

member value description
Sha1 "sha1" SHA-1, a 40-character lowercase hex digest