diff --git a/basis/checksums/common/common.factor b/basis/checksums/common/common.factor index 8e062bb0d1..aaa2e97357 100644 --- a/basis/checksums/common/common.factor +++ b/basis/checksums/common/common.factor @@ -39,16 +39,18 @@ GENERIC: checksum-block ( bytes checksum-state -- ) 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 ; diff --git a/basis/checksums/sha/sha-tests.factor b/basis/checksums/sha/sha-tests.factor index 7ac9e17243..08be4db777 100644 --- a/basis/checksums/sha/sha-tests.factor +++ b/basis/checksums/sha/sha-tests.factor @@ -67,3 +67,11 @@ IN: checksums.sha.tests <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