checksums: remove hex-string in favor of math.parser:bytes>hex-string.
parent
236f962323
commit
0d2859124e
|
@ -1,6 +1,6 @@
|
||||||
USING: kernel io strings byte-arrays sequences namespaces math
|
USING: kernel io strings byte-arrays sequences namespaces math
|
||||||
parser checksums.hmac tools.test checksums.md5 checksums.sha
|
math.parser parser checksums.hmac tools.test checksums.md5
|
||||||
checksums ;
|
checksums.sha checksums ;
|
||||||
IN: checksums.hmac.tests
|
IN: checksums.hmac.tests
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -39,10 +39,10 @@ IN: checksums.hmac.tests
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7" }
|
{ "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" }
|
{ "167f928588c5cc2eef8e3093caa0e87c9ff566a14794aa61648d81621a2a40c6" }
|
||||||
[
|
[
|
||||||
"what do ya want for nothing?"
|
"what do ya want for nothing?"
|
||||||
"JefeJefeJefeJefeJefeJefeJefeJefe" sha-256 hmac-bytes hex-string
|
"JefeJefeJefeJefeJefeJefeJefeJefe" sha-256 hmac-bytes bytes>hex-string
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: byte-arrays checksums checksums.md5 io.encodings.binary
|
USING: byte-arrays checksums checksums.md5 io.encodings.binary
|
||||||
io.streams.byte-array kernel math namespaces tools.test
|
io.streams.byte-array kernel math math.parser namespaces
|
||||||
sequences ;
|
tools.test sequences ;
|
||||||
IN: checksums.md5.tests
|
IN: checksums.md5.tests
|
||||||
|
|
||||||
{ "d41d8cd98f00b204e9800998ecf8427e" } [ "" >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 hex-string ] unit-test
|
{ "0cc175b9c0f1b6a831c399e269772661" } [ "a" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
|
||||||
{ "900150983cd24fb0d6963f7d28e17f72" } [ "abc" >byte-array md5 checksum-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 hex-string ] unit-test
|
{ "f96b697d7cb7938d525a2f31aaf161d0" } [ "message digest" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
|
||||||
{ "c3fcd3d76192e4007dfb496cca67e13b" } [ "abcdefghijklmnopqrstuvwxyz" >byte-array md5 checksum-bytes hex-string ] unit-test
|
{ "c3fcd3d76192e4007dfb496cca67e13b" } [ "abcdefghijklmnopqrstuvwxyz" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
|
||||||
{ "d174ab98d277d9f5a5611c2c9f419d9f" } [ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" >byte-array md5 checksum-bytes hex-string ] unit-test
|
{ "d174ab98d277d9f5a5611c2c9f419d9f" } [ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
|
||||||
{ "57edf4a22be3c955ac49da2e2107b67a" } [ "12345678901234567890123456789012345678901234567890123456789012345678901234567890" >byte-array md5 checksum-bytes hex-string ] unit-test
|
{ "57edf4a22be3c955ac49da2e2107b67a" } [ "12345678901234567890123456789012345678901234567890123456789012345678901234567890" >byte-array md5 checksum-bytes bytes>hex-string ] unit-test
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,8 +32,8 @@ ARTICLE: "checksums.openssl" "OpenSSL checksums"
|
||||||
"An error thrown if the digest name is unrecognized:"
|
"An error thrown if the digest name is unrecognized:"
|
||||||
{ $subsections unknown-digest }
|
{ $subsections unknown-digest }
|
||||||
"An example where we compute the SHA1 checksum of a string using the OpenSSL implementation of SHA1:"
|
"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:"
|
"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"
|
ABOUT: "checksums.openssl"
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
USING: arrays checksums checksums.sha checksums.sha.private
|
USING: arrays checksums checksums.sha checksums.sha.private
|
||||||
io.encodings.binary io.streams.byte-array kernel math
|
io.encodings.binary io.streams.byte-array kernel math
|
||||||
namespaces sequences tools.test ;
|
math.parser namespaces sequences tools.test ;
|
||||||
IN: checksums.sha.tests
|
IN: checksums.sha.tests
|
||||||
|
|
||||||
: test-checksum ( text identifier -- checksum )
|
: test-checksum ( text identifier -- checksum )
|
||||||
checksum-bytes hex-string ;
|
checksum-bytes bytes>hex-string ;
|
||||||
|
|
||||||
{ "a9993e364706816aba3e25717850c26c9cd0d89d" } [ "abc" sha1 checksum-bytes hex-string ] unit-test
|
{ "a9993e364706816aba3e25717850c26c9cd0d89d" } [ "abc" sha1 checksum-bytes bytes>hex-string ] unit-test
|
||||||
{ "84983e441c3bd26ebaae4aa1f95129e5e54670f1" } [ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" sha1 checksum-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...
|
! [ "34aa973cd4c4daa4f61eeb2bdbad27316534016f" ] [ 1000000 CHAR: a fill string>sha1str ] unit-test ! takes a long time...
|
||||||
{ "dea356a2cddd90c7a7ecedc5ebb563934f460452" } [ "0123456701234567012345670123456701234567012345670123456701234567"
|
{ "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" }
|
{ "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" }
|
||||||
|
|
|
@ -4,14 +4,6 @@ IN: checksums
|
||||||
HELP: checksum
|
HELP: checksum
|
||||||
{ $class-description "The class of checksum algorithms." } ;
|
{ $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
|
HELP: checksum-stream
|
||||||
{ $values { "stream" "an input stream" } { "checksum" "a checksum specifier" } { "value" byte-array } }
|
{ $values { "stream" "an input stream" } { "checksum" "a checksum specifier" } { "value" byte-array } }
|
||||||
{ $contract "Computes the checksum of all data read from the stream." }
|
{ $contract "Computes the checksum of all data read from the stream." }
|
||||||
|
@ -69,7 +61,6 @@ $nl
|
||||||
"Utilities:"
|
"Utilities:"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
checksum-file
|
checksum-file
|
||||||
hex-string
|
|
||||||
}
|
}
|
||||||
"Checksum implementations:"
|
"Checksum implementations:"
|
||||||
{ $subsections "checksums.crc32" }
|
{ $subsections "checksums.crc32" }
|
||||||
|
|
|
@ -60,6 +60,3 @@ M: checksum checksum-lines
|
||||||
! binary <file-reader>. We use the lower-level form
|
! binary <file-reader>. We use the lower-level form
|
||||||
! so that we can move io.encodings.binary to basis/.
|
! so that we can move io.encodings.binary to basis/.
|
||||||
[ normalize-path (file-reader) ] dip checksum-stream ;
|
[ normalize-path (file-reader) ] dip checksum-stream ;
|
||||||
|
|
||||||
: hex-string ( seq -- str )
|
|
||||||
[ >hex 2 CHAR: 0 pad-head ] { } map-as concat ;
|
|
||||||
|
|
Loading…
Reference in New Issue