1 USING: byte-arrays help.markup help.syntax ;
5 { $class-description "The class of checksum algorithms." } ;
8 { $values { "stream" "an input stream" } { "checksum" "a checksum specifier" } { "value" byte-array } }
9 { $contract "Computes the checksum of all data read from the stream." }
10 { $side-effects "stream" } ;
13 { $values { "bytes" "a sequence of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } }
14 { $contract "Computes the checksum of all data in a sequence." }
17 "USING: checksums checksums.crc32 prettyprint ;"
18 "B{ 1 10 100 } crc32 checksum-bytes ."
24 { $values { "lines" "a sequence of sequences of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } }
25 { $contract "Computes the checksum of all data in a sequence." }
28 "USING: checksums checksums.crc32 prettyprint ;"
30 \"Take me out to the ball game\"
31 \"Take me out with the crowd\"
32 } crc32 checksum-lines ."
38 { $values { "path" "a pathname specifier" } { "checksum" "a checksum specifier" } { "value" byte-array } }
39 { $description "Computes the checksum of all data in a file." }
42 ! This example fails on Windows if you ``git clone`` with Windows line-endings
44 "USING: checksums checksums.crc32 prettyprint ;"
45 "\"resource:core/checksums/crc32/crc-me.txt\" crc32 checksum-file ."
46 "B{ 196 202 117 155 }"
50 ARTICLE: "checksums" "Checksums"
51 "A " { $emphasis "checksum" } " is a function mapping sequences of bytes to fixed-length strings. While checksums are not one-to-one, a good checksum should have a low probability of collision. Additionally, some checksum algorithms are designed to be hard to reverse, in the sense that finding an input string which hashes to a given checksum string requires a brute-force search."
53 "Checksums are instances of a class:"
54 { $subsections checksum }
55 "Operations on checksums:"
62 "Checksums should implement at least one of " { $link checksum-bytes } " and " { $link checksum-stream } ". Implementing " { $link checksum-lines } " is optional."
64 "Checksums can also implement a stateful checksum protocol that allows users to push bytes when needed and then at a later point request the checksum value. The default implementation is not very efficient, storing all of the bytes and then calling " { $link checksum-bytes } " when " { $link get-checksum } " is requested."
67 initialize-checksum-state
74 "Checksum implementations:"
76 { "CRC32 checksum" "checksums.crc32" }
77 { "MD5 checksum" "checksums.md5" }
78 { "SHA checksums" "checksums.sha" }
79 { "Adler-32 checksum" "checksums.adler-32" }
80 { "OpenSSL checksums" "checksums.openssl" }
81 { "Internet checksum" "checksums.internet" }
82 { "Checksum using an external utility" "checksums.process" }