USING: kernel io strings byte-arrays sequences namespaces math
-parser checksums.hmac tools.test checksums.md5 checksums.sha
-checksums ;
+math.parser parser checksums.hmac tools.test checksums.md5
+checksums.sha checksums ;
IN: checksums.hmac.tests
{
] unit-test
{ "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7" }
-[ "Hi There" 20 0xb <string> sha-256 hmac-bytes hex-string ] unit-test
+[ "Hi There" 20 0xb <string> sha-256 hmac-bytes bytes>hex-string ] unit-test
{ "167f928588c5cc2eef8e3093caa0e87c9ff566a14794aa61648d81621a2a40c6" }
[
"what do ya want for nothing?"
- "JefeJefeJefeJefeJefeJefeJefeJefe" sha-256 hmac-bytes hex-string
+ "JefeJefeJefeJefeJefeJefeJefeJefe" sha-256 hmac-bytes bytes>hex-string
] unit-test
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: byte-arrays checksums checksums.md5 io.encodings.binary
-io.streams.byte-array kernel math namespaces tools.test
-sequences ;
+io.streams.byte-array kernel math math.parser namespaces
+tools.test sequences ;
IN: checksums.md5.tests
-{ "d41d8cd98f00b204e9800998ecf8427e" } [ "" >byte-array md5 checksum-bytes hex-string ] unit-test
-{ "0cc175b9c0f1b6a831c399e269772661" } [ "a" >byte-array md5 checksum-bytes hex-string ] unit-test
-{ "900150983cd24fb0d6963f7d28e17f72" } [ "abc" >byte-array md5 checksum-bytes hex-string ] unit-test
-{ "f96b697d7cb7938d525a2f31aaf161d0" } [ "message digest" >byte-array md5 checksum-bytes hex-string ] unit-test
-{ "c3fcd3d76192e4007dfb496cca67e13b" } [ "abcdefghijklmnopqrstuvwxyz" >byte-array md5 checksum-bytes hex-string ] unit-test
-{ "d174ab98d277d9f5a5611c2c9f419d9f" } [ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" >byte-array md5 checksum-bytes hex-string ] unit-test
-{ "57edf4a22be3c955ac49da2e2107b67a" } [ "12345678901234567890123456789012345678901234567890123456789012345678901234567890" >byte-array md5 checksum-bytes hex-string ] unit-test
+{ "d41d8cd98f00b204e9800998ecf8427e" } [ "" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
+{ "0cc175b9c0f1b6a831c399e269772661" } [ "a" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
+{ "900150983cd24fb0d6963f7d28e17f72" } [ "abc" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
+{ "f96b697d7cb7938d525a2f31aaf161d0" } [ "message digest" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
+{ "c3fcd3d76192e4007dfb496cca67e13b" } [ "abcdefghijklmnopqrstuvwxyz" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
+{ "d174ab98d277d9f5a5611c2c9f419d9f" } [ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
+{ "57edf4a22be3c955ac49da2e2107b67a" } [ "12345678901234567890123456789012345678901234567890123456789012345678901234567890" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
{
"An error thrown if the digest name is unrecognized:"
{ $subsections unknown-digest }
"An example where we compute the SHA1 checksum of a string using the OpenSSL implementation of SHA1:"
-{ $example "USING: byte-arrays checksums checksums.openssl ;" "\"hello world\" >byte-array openssl-sha1 checksum-bytes hex-string ." "\"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\"" }
+{ $example "USING: byte-arrays checksums checksums.openssl math.parser ;" "\"hello world\" >byte-array openssl-sha1 checksum-bytes bytes>hex-string ." "\"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\"" }
"If we use the Factor implementation, we get the same result, just slightly slower:"
-{ $example "USING: byte-arrays checksums checksums.sha ;" "\"hello world\" >byte-array sha1 checksum-bytes hex-string ." "\"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\"" } ;
+{ $example "USING: byte-arrays checksums checksums.sha math.parser ;" "\"hello world\" >byte-array sha1 checksum-bytes bytes>hex-string ." "\"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\"" } ;
ABOUT: "checksums.openssl"
USING: arrays checksums checksums.sha checksums.sha.private
io.encodings.binary io.streams.byte-array kernel math
-namespaces sequences tools.test ;
+math.parser namespaces sequences tools.test ;
IN: checksums.sha.tests
: test-checksum ( text identifier -- checksum )
- checksum-bytes hex-string ;
+ checksum-bytes bytes>hex-string ;
-{ "a9993e364706816aba3e25717850c26c9cd0d89d" } [ "abc" sha1 checksum-bytes hex-string ] unit-test
-{ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" } [ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" sha1 checksum-bytes hex-string ] unit-test
+{ "a9993e364706816aba3e25717850c26c9cd0d89d" } [ "abc" sha1 checksum-bytes bytes>hex-string ] unit-test
+{ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" } [ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" sha1 checksum-bytes bytes>hex-string ] unit-test
! [ "34aa973cd4c4daa4f61eeb2bdbad27316534016f" ] [ 1000000 CHAR: a fill string>sha1str ] unit-test ! takes a long time...
{ "dea356a2cddd90c7a7ecedc5ebb563934f460452" } [ "0123456701234567012345670123456701234567012345670123456701234567"
-10 swap <array> concat sha1 checksum-bytes hex-string ] unit-test
+10 swap <array> concat sha1 checksum-bytes bytes>hex-string ] unit-test
{ "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" }
HELP: checksum
{ $class-description "The class of checksum algorithms." } ;
-HELP: hex-string
-{ $values { "seq" sequence } { "str" string } }
-{ $description "Converts a sequence of values from 0-255 to a string of hex numbers from 0-ff." }
-{ $examples
- { $example "USING: checksums io ;" "B{ 1 2 3 4 } hex-string print" "01020304" }
-}
-{ $notes "Numbers are zero-padded on the left." } ;
-
HELP: checksum-stream
{ $values { "stream" "an input stream" } { "checksum" "a checksum specifier" } { "value" byte-array } }
{ $contract "Computes the checksum of all data read from the stream." }
"Utilities:"
{ $subsections
checksum-file
- hex-string
}
"Checksum implementations:"
{ $subsections "checksums.crc32" }
! binary <file-reader>. We use the lower-level form
! so that we can move io.encodings.binary to basis/.
[ normalize-path (file-reader) ] dip checksum-stream ;
-
-: hex-string ( seq -- str )
- [ >hex 2 CHAR: 0 pad-head ] { } map-as concat ;