]> gitweb.factorcode.org Git - factor.git/commitdiff
Updated to work with .77 cvs.
authorDoug Coleman <erg@trifocus.net>
Sat, 20 Aug 2005 08:32:53 +0000 (08:32 +0000)
committerDoug Coleman <erg@trifocus.net>
Sat, 20 Aug 2005 08:32:53 +0000 (08:32 +0000)
Uses 'content' word as per slava's blog.
Added  'file>md5' and 'stream>md5'.

contrib/crypto/md5.factor

index 6a4facc23397087e3b85dc730b170c75663e86d8..d089f88c0e1294c14668e4ef7942266aa2f73471 100644 (file)
@@ -17,6 +17,10 @@ SYMBOL: old-d
 : nth-int ( string n -- int )
     4 * dup 4 + rot subseq le> ;
 
+: contents ( stream -- string )
+    #! Read the entire stream into a string.
+           4096 <sbuf> [ stream-copy ] keep >string ;
+
 : initialize ( -- )
     HEX: 67452301 dup a set old-a set
     HEX: efcdab89 dup b set old-b set
@@ -179,7 +183,11 @@ SYMBOL: old-d
     64 * dup 64 + rot subseq ;
 
 : hex-string ( str -- str )
-    [ >hex 2 CHAR: 0 pad-left ] map concat ;
+       [
+               [
+                       >hex 2 48 pad-left %
+               ] each
+       ] make-string ;
 
 : get-md5 ( -- str )
     [
@@ -193,6 +201,15 @@ SYMBOL: old-d
         2drop get-md5
     ] with-scope ;
 
+: stream>md5 ( stream -- md5 )
+       [
+               contents string>md5
+       ] with-scope ;
+: file>md5 ( file -- md5 )
+       [
+               <file-reader> stream>md5
+       ] with-scope ;
+
 : test-md5 ( -- )
     [ "d41d8cd98f00b204e9800998ecf8427e" ] [ "" string>md5 ] unit-test
     [ "0cc175b9c0f1b6a831c399e269772661" ] [ "a" string>md5 ] unit-test