1 import Base 2 import ./state.bend as S 3 import ./packed.bend as P 4 5 # Exactly eight big-endian U32 words (32 bytes), with no list allocation. 6 def digest(s: S.State) -> Array: 7 match s: 8 case S.H{a,b,c,d,e,f,g,h}: 9 ANode{ANode{ANode{ALeaf{a},ALeaf{b}},ANode{ALeaf{c},ALeaf{d}}},ANode{ANode{ALeaf{e},ALeaf{f}},ANode{ALeaf{g},ALeaf{h}}}} 10 11 def result(r: Maybe<&2,S.State>) -> Maybe<&1,Array>: 12 match r: 13 case None{}: None{} 14 case Some{s}: Some{digest(s)} 15 16 def sha256(input: Array, length: Nat) -> Maybe<&1,Array>: 17 result(P.hash(input,length))