GENERIC: get-checksum ( checksum-state -- value )
: add-checksum-bytes ( checksum-state data -- checksum-state' )
- over bytes>> [ push-all ] keep
- [ dup length pick block-size>> >= ]
[
- over block-size>> cut-slice [
- over checksum-block
- [ block-size>> ] keep [ + ] change-bytes-read
- ] dip
- ] while
- >byte-vector
- [ >>bytes ] [ length [ + ] curry change-bytes-read ] bi ;
+ over bytes>> [ push-all ] keep
+ [ dup length pick block-size>> >= ]
+ [
+ over block-size>> cut-slice [
+ over checksum-block
+ [ block-size>> ] keep [ + ] change-bytes-read
+ ] dip
+ ] while
+ >byte-vector >>bytes
+ ] keep
+ length [ + ] curry change-bytes-read ;
: add-checksum-stream ( checksum-state stream -- checksum-state )
[ [ add-checksum-bytes ] each-block ] with-input-stream ;
<sha-224-state> "asdf" binary <byte-reader> add-checksum-stream
[ get-checksum ] [ get-checksum ] bi =
] unit-test
+
+
+CONSTANT: bytes-a B{ 0 1 0 0 0 0 0 0 }
+CONSTANT: bytes-b B{ 1 2 3 4 5 6 7 8 }
+{ t } [
+ sha1 initialize-checksum-state bytes-a bytes-b append add-checksum-bytes get-checksum
+ sha1 initialize-checksum-state bytes-a add-checksum-bytes bytes-b add-checksum-bytes get-checksum
+] unit-test