Skip to content
heff

std.sha1

SHA-1, the hash of FIPS 180-4: any bytes to 20 bytes. It is broken (two different files of the same SHA-1 are known): it is here for what still names things by it, git’s objects among them, not to tell bytes that may have been made to collide apart — that is std.sha256’s. Written in heff, a block of 64 bytes at a time.

import bytes as Bytes
import std.sha1 as SHA1
-- | the name git gives a file's content, a blob
blobName : Bytes -> Bytes
blobName content =
SHA1.digest
(Bytes.concat
[Bytes.fromString ("blob " ^ debug (Bytes.length content)), b[0], content])

digest

digest : Bytes -> Bytes

The SHA-1 hash of the bytes, 20 bytes.

>>> digest Bytes.empty == b[0xda39a3ee5e6b4b0d::64, 0x3255bfef95601890::64, 0xafd80709::32]
True
>>> digest (Bytes.fromString "abc") == b[0xa9993e364706816a::64, 0xba3e25717850c26c::64, 0x9cd0d89d::32]
True
>>> digest (Bytes.fromString "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") == b[0x84983e441c3bd26e::64, 0xbaae4aa1f95129e5::64, 0xe54670f1::32]
True
>>> digest (Bytes.fromString "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu") == b[0xa49b2446a02c645b::64, 0xf419f995b6709125::64, 0x3a04a259::32]
True