Skip to content

State

Supertype for stateful digest handles.

Subtype of Sink. Putting a Str or Bin value updates the digest state with its bytes.

Methods

digest() -> Bin

Returns the current digest bytes without consuming the handle.

Returns

A snapshot of the digest so far.

Example

let state = Blake3()
state.update "abc"
let first = state.digest()
let second = state.digest()
assert_eq $first $second
state.update "def"
assert_eq "${state.digest():x}"
  b34b56076712fd7fb9c067245a6c85e16174b3ef2e35df7b56b7f164e5c36446

update data -> State

Updates the digest state with the bytes of data.

Parameters

NameTypeDescription
data (Str | Bin) Input to hash.

Returns

The same state, for chaining.

Example

let state = Blake3()
state.update "ab"
state.update b"c"
assert_eq "${state.digest():x}"
  6437b3ac38465133ffb63b75273a8db548c558465d79db03fd359c6cd5bd9d85

let sink = Blake3()
sink.put "ab"
sink.put b"c"
assert_eq $sink.digest() (blake3 "abc")
Open in playground