Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

lib/digest.x

SHA-256 digests of Strings and streams.

Primary API

FunctionSummary
File.sha256Returns the SHA-256 digest of the bytes from the current position of file to its end, leaving the stream at end of file and open.
String.sha256Returns the SHA-256 digest of the bytes of text; NULL is empty text.

File

File.sha256

String File.sha256(File file)

Returns the SHA-256 digest of the bytes from the current position of file to its end, leaving the stream at end of file and open.

Raises: <io-fail> on a stream read error.

Source: lib/digest.x:120

String

String.sha256

String String.sha256(String text)

Returns the SHA-256 digest of the bytes of text; NULL is empty text.

Source: lib/digest.x:110

Design notes

A digest is the 64-character lowercase hexadecimal String that shasum -a 256 prints. A stream digest reads raw bytes, so a file that holds NUL bytes, which a String cannot, hashes like any other.

Tests and examples

make verify (unittest/test-digest.x).