sha1

SHA-1 hashing helpers for whole-input and incremental hashing.


sha1 (source -- digest)

Computes one SHA-1 digest for one complete source span.


ShaCounter

Incremental SHA-1 state that accepts appended input chunks and produces one final digest.

Fields

Methods

Remarks


Accepted sources


Digest format


Whole-input and incremental relation


Sha1Internal

Low-level helpers used by ShaCounter and sha1.


Examples

Incremental and direct hashing agree

"sha1" use
"control" use

{} () {} [
  direct: "abc" sha1;
  counter: ShaCounter;
  "ab" @counter.append
  "c" @counter.append
  incremental: @counter.finish;
  direct incremental same printStack _:;
] "main" exportFunction

Expected Output During Compilation

TRUE

Digest bytes of "abc"

"sha1" use
"String" use
"control" use

{} Int32 {} [
  digest: "abc" sha1;
  out: String;

  20 [
    byte: i digest @;
    i 0 > [" " @out.catString] when
    byte 16n8 < ["0" @out.catString] when
    byte @out.catHex
  ] times

  @out.getStringView print
  0
] "main" exportFunction

Expected Output

A9 99 3E 36 47 06 81 6A BA 3E 25 71 78 50 C2 6C 9C D0 D8 9D

See also