IF Commons GitHub

sha256

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-crypto FR-001

SHA-256 through Web Crypto (crypto.subtle, in every runtime and browser), and a typed Sha256: 64 lower-case hexadecimal digits that the compiler keeps apart from any other string, so a checksum is never confused with a version or a path (commons 0001-crypto FR-001). Taken from the machine setup's result.ts and net.ts, and the many call sites that write the hex loop by hand.

import { sha256, sha256Of } from "./sha256.ts";
const sum = await sha256(new TextEncoder().encode("abc"));
sum === sha256Of("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"); // true

Source: commons/crypto/src/sha256.ts

5 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

parseSha256Sumsfunction
function parseSha256Sums(text: string): ReadonlyMap<string, Sha256>

The lines of a sha256sum or SHASUMS256.txt file, as file name to checksum; lines that are not a checksum and a name are skipped.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

sameSha256function
function sameSha256(a: Sha256, b: Sha256): boolean

Whether two checksums are the same, compared in constant time for their length.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

sha256function
function sha256(data: string | Uint8Array<ArrayBufferLike>): Promise<Sha256>

The SHA-256 of bytes, or of text as UTF-8.

Imported by 23 tests of the run (23 passed, 0 failed): the library's results

sha256Offunction
function sha256Of(text: string): Sha256 | undefined

The text as a checksum where it is one (upper-case digits are lowered), else undefined.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Sha256type
type Sha256 = Brand<string, "Sha256">;

64 lower-case hexadecimal digits: a SHA-256 checksum.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.