]> gitweb.factorcode.org Git - factor.git/commitdiff
checksums.common: Checksums was calculating the new length based on the entire array...
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 9 Jul 2016 18:53:30 +0000 (13:53 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 9 Jul 2016 18:53:30 +0000 (13:53 -0500)
Reported by Александр Ilin.

basis/checksums/common/common.factor
basis/checksums/sha/sha-tests.factor

index 8e062bb0d17f47a9918488778b3cfe4991b97f87..aaa2e9735776abd469b6073e6545e2cb646283dd 100644 (file)
@@ -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 ;
index 7ac9e17243a4a8772707cc4a640dda0c47f5d536..08be4db7779c8ca66d61d055ca7bedea6885d545 100644 (file)
@@ -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