std/digest/lib
std/digest/src/lib.trb
Message digests: Sha256 and Sha512, the SHA-256 and SHA-512 of FIPS 180-4, and the Digest both answer.
SHA-256 is what the package manager pins a package by (docs/design/RELEASE.md section 7.2) and what a download is
checked against; SHA-512 is what Ed25519 hashes with (std/signature).
Ordinary TorbScript with no native. SHA-256 works over Int, every word kept below 2^32 by a mask, so nothing
overflows; SHA-512 over UInt64 and its wrapping sum. The same bytes give the same digest in both back ends.
Examples
print Sha256.of("abc".bytes().toList()).hex()
// prints ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
var hasher = Sha256()
hasher.add "ab".bytes().toList()
hasher.add "c".bytes().toList()
print hasher.finished().hex()
type Digest
type Digest with Show
What a hash function answers: its bytes, most significant first, shown as lowercase hexadecimal.
type Sha256
type Sha256
SHA-256, fed in pieces: Sha256.add takes the next bytes and Sha256.finished answers the digest of everything added
so far without changing the hasher, so a hasher can be read, fed more, and read again.