1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
//! This crate provides an implementation of various hash functions with a straightforward interface for computing digests of bytes, files, directories, and more.
//!
//! For a low-level interface, you can explore the [`chksum_hash`] crate.
//!
//! # Setup
//!
//! To use this crate, add the following entry to your `Cargo.toml` file in the `dependencies` section:
//!
//! ```toml
//! [dependencies]
//! chksum = "0.4.0"
//! ```
//!
//! Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand:
//!
//! ```sh
//! cargo add chksum
//! ```
//!
//! # Usage
//!
//! Use the [`chksum`] function with the desired algorithm to calculate digest of file, directory and so on.
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::{chksum, SHA2_256};
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = chksum::<SHA2_256>(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! Alternatively, use the `chksum` function directly from the chosen hash module.
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha2_256::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! # Input Types
//!
//! ## Bytes
//!
//! ### Array
//!
//! ```rust
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper() -> Result<()> {
//! let data = [0, 1, 2, 3];
//! let digest = sha2_256::chksum(data)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ### Vec
//!
//! ```rust
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper() -> Result<()> {
//! let data = vec![0, 1, 2, 3];
//! let digest = sha2_256::chksum(data)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ### Slice
//!
//! ```rust
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper() -> Result<()> {
//! let data = &[0, 1, 2, 3];
//! let digest = sha2_256::chksum(data)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## Strings
//!
//! ### str
//!
//! ```rust
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper() -> Result<()> {
//! let data = "&str";
//! let digest = sha2_256::chksum(data)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ### String
//!
//! ```rust
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper() -> Result<()> {
//! let data = String::from("String");
//! let digest = sha2_256::chksum(data)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## File
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha2_256::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## Directory
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::read_dir;
//!
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let readdir = read_dir(path)?;
//! let digest = sha2_256::chksum(readdir)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## Path
//!
//! ```rust
//! # use std::path::Path;
//! use std::path::PathBuf;
//!
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let path = PathBuf::from(path);
//! let digest = sha2_256::chksum(path)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## Standard Input
//!
//! ```rust
//! use std::io::stdin;
//!
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper() -> Result<()> {
//! let stdin = stdin();
//! let digest = sha2_256::chksum(stdin)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! # Algorithms
//!
//! ## MD5
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::md5;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = md5::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "5c71dbb287630d65ca93764c34d9aa0d"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## SHA-1
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha1;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha1::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "9fc42adac31303d68b444e6129f13f6093a0e045"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## SHA-2 224
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha2_224;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha2_224::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "90382cbfda2656313ad61fd74b32ddfa4bcc118f660bd4fba9228ced"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## SHA-2 256
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha2_256;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha2_256::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "44752f37272e944fd2c913a35342eaccdd1aaf189bae50676b301ab213fc5061"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## SHA-2 384
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha2_384;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha2_384::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "12ecdfd463a85a301b7c29a43bf4b19cdfc6e5e86a5f40396aa6ae3368a7e5b0ed31f3bef2eb3071577ba610b4ed1cb8"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! ## SHA-2 512
//!
//! ```rust
//! # use std::path::Path;
//! use std::fs::File;
//!
//! # use chksum::Result;
//! use chksum::sha2_512;
//!
//! # fn wrapper(path: &Path) -> Result<()> {
//! let file = File::open(path)?;
//! let digest = sha2_512::chksum(file)?;
//! assert_eq!(
//! digest.to_hex_lowercase(),
//! "ed59c5759a9ece516cec0c0623142d0e9fe70a27d750eee7fd38f4550d50addd873d0fa1a51fc823c1e3d5cada203f4a05d8325caacb7d3e0727a701f3f07e5f"
//! );
//! # Ok(())
//! # }
//! ```
//!
//! # Features
//!
//! ## Algorithms
//!
//! Cargo features are utilized to enable or disable specific hash algorithms.
//!
//! * `md5` enables MD5, accessible via the [`md5`] module.
//! * `sha1` enables SHA-1, accessible via the [`sha1`] module.
//! * `sha2-224` enables SHA-2 224, accessible via the [`sha2_224`] module.
//! * `sha2-256` enables SHA-2 256, accessible via the [`sha2_256`] module.
//! * `sha2-384` enables SHA-2 384, accessible via the [`sha2_384`] module.
//! * `sha2-512` enables SHA-2 512, accessible via the [`sha2_512`] module.
//!
//! By default, all of these features are enabled.
//!
//! To customize your setup, disable the default features and enable only those that you need in your `Cargo.toml` file:
//!
//! ```toml
//! [dependencies]
//! chksum = { version = "0.4.0", default-features = false, features = ["sha1", "sha2-256", "sha2-512"] }
//! ```
//!
//! Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand:
//!
//! ```shell
//! cargo add chksum --no-default-features --features sha1,sha2-256,sha2-512
//! ```
//!
//! ## Extra Options
//!
//! Cargo features are also utilized to enable extra options.
//!
//! * `reader` enables the `reader` module with the `Reader` struct within each variant module.
//! * `writer` enables the `writer` module with the `Writer` struct within each variant module.
//!
//! By default, neither of these features is enabled.
//!
//! To customize your setup, disable the default features and enable only those that you need in your `Cargo.toml` file:
//!
//! ```toml
//! [dependencies]
//! chksum = { version = "0.4.0", features = ["reader", "writer"] }
//! ```
//!
//! Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand:
//!
//! ```shell
//! cargo add chksum --features reader,writer
//! ```
//!
//! # License
//!
//! This crate is licensed under the MIT License.
pub use ;
pub use ;
use chksum_hash;
pub use chksum_md5 as md5;
pub use MD5;
pub use chksum_reader as reader;
pub use Reader;
pub use chksum_sha1 as sha1;
pub use SHA1;
pub use chksum_sha2 as sha2;
pub use sha2_224;
pub use sha2_256;
pub use sha2_384;
pub use sha2_512;
pub use SHA2_224;
pub use SHA2_256;
pub use SHA2_384;
pub use SHA2_512;
pub use chksum_writer as writer;
pub use Writer;