Standard Library
std.hash
Digests and checksums: SHA-256/512, HMAC-SHA256, CRC32, and FNV-1a.
Exported functions
pub def sha256(text: String) -> String
Compute the SHA-256 digest of UTF-8 text as lowercase hex.
Examples
use hash from "std.hash"
@println(hash.sha256("hello"))
# 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824pub def sha256_bytes(data: List[Int]) -> List[Int]
Compute the SHA-256 digest of bytes.
Examples
use hash from "std.hash"
use encoding from "std.encoding"
const digest = hash.sha256_bytes([104, 101, 108, 108, 111])
@println(encoding.hex_encode(digest) == hash.sha256("hello")) # truepub def sha512(text: String) -> String
Compute the SHA-512 digest of UTF-8 text as lowercase hex.
pub def sha512_bytes(data: List[Int]) -> List[Int]
Compute the SHA-512 digest of bytes.
pub def hmac_sha256(key: String, message: String) -> String
Compute an HMAC-SHA256 tag over UTF-8 text as lowercase hex.
Examples
use hash from "std.hash"
const tag = hash.hmac_sha256("example-key", "message")
@println(@len(tag)) # 64 hexadecimal characterspub def hmac_sha256_bytes(key: List[Int], message: List[Int]) -> List[Int]
Compute an HMAC-SHA256 tag over bytes.
pub def crc32(text: String) -> Int
Compute the CRC32 checksum of UTF-8 text.
Examples
use hash from "std.hash"
@println(hash.crc32("123456789")) # 3421780262pub def crc32_bytes(data: List[Int]) -> Int
Compute the CRC32 checksum of bytes.
pub def fnv1a64(text: String) -> Int
Compute the FNV-1a 64-bit hash of UTF-8 text.
pub def fnv1a64_bytes(data: List[Int]) -> Int
Compute the FNV-1a 64-bit hash of bytes.