]> gitweb.factorcode.org Git - factor.git/blob - core/checksums/checksums-docs.factor
merge project-euler.factor
[factor.git] / core / checksums / checksums-docs.factor
1 USING: help.markup help.syntax kernel math sequences quotations
2 math.private byte-arrays strings ;
3 IN: checksums
4
5 HELP: checksum
6 { $class-description "The class of checksum algorithms." } ;
7
8 HELP: hex-string
9 { $values { "seq" "a sequence" } { "str" "a string" } }
10 { $description "Converts a sequence of values from 0-255 to a string of hex numbers from 0-ff." }
11 { $examples
12     { $example "USING: checksums io ;" "B{ 1 2 3 4 } hex-string print" "01020304" }
13 }
14 { $notes "Numbers are zero-padded on the left." } ;
15
16 HELP: checksum-stream
17 { $values { "stream" "an input stream" } { "checksum" "a checksum specifier" } { "value" byte-array } }
18 { $contract "Computes the checksum of all data read from the stream." }
19 { $side-effects "stream" } ;
20
21 HELP: checksum-bytes
22 { $values { "bytes" "a sequence of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } }
23 { $contract "Computes the checksum of all data in a sequence." }
24 { $examples
25     { $example
26         "USING: checksums checksums.crc32 prettyprint ;"
27         "B{ 1 10 100 } crc32 checksum-bytes ."
28         "B{ 78 179 254 238 }"
29     }
30 } ;
31
32 HELP: checksum-lines
33 { $values { "lines" "a sequence of sequences of bytes" } { "checksum" "a checksum specifier" } { "value" byte-array } }
34 { $contract "Computes the checksum of all data in a sequence." }
35 { $examples
36     { $example
37         "USING: checksums checksums.crc32 prettyprint ;"
38 """{
39     "Take me out to the ball game"
40     "Take me out with the crowd"
41 } crc32 checksum-lines ."""
42         "B{ 111 205 9 27 }"
43     }
44 } ;
45
46 HELP: checksum-file
47 { $values { "path" "a pathname specifier" } { "checksum" "a checksum specifier" } { "value" byte-array } }
48 { $contract "Computes the checksum of all data in a file." }
49 { $examples
50     { $example
51         "USING: checksums checksums.crc32 prettyprint ;"
52         """"resource:license.txt" crc32 checksum-file ."""
53         "B{ 100 139 199 92 }"
54     }
55 } ;
56
57 ARTICLE: "checksums" "Checksums"
58 "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."
59 $nl
60 "Checksums are instances of a class:"
61 { $subsections checksum }
62 "Operations on checksums:"
63 { $subsections
64     checksum-bytes
65     checksum-stream
66     checksum-lines
67 }
68 "Checksums should implement at least one of " { $link checksum-bytes } " and " { $link checksum-stream } ". Implementing " { $link checksum-lines } " is optional."
69 $nl
70 "Utilities:"
71 { $subsections
72     checksum-file
73     hex-string
74 }
75 "Checksum implementations:"
76 { $subsections "checksums.crc32" }
77 { $vocab-subsection "MD5 checksum" "checksums.md5" }
78 { $vocab-subsection "SHA checksums" "checksums.sha" }
79 { $vocab-subsection "Adler-32 checksum" "checksums.adler-32" }
80 { $vocab-subsection "OpenSSL checksums" "checksums.openssl" } ;
81
82 ABOUT: "checksums"