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
//! Tool for making/verifying checksums of directory trees. //! //! ## SYNOPSIS //! //! [`checksums`](https://github.com/nabijaczleweli/checksums) [OPTIONS] [DIRECTORY] //! //! ## DESCRIPTION //! //! Tool for making/verifying checksums of directory trees. //! //! Use the generated checksums to automatically verify file/directory tree //! correctness. //! //! ## OPTIONS //! //! -a --algorithm <algorithm> //! //! ```text //! Set the hashing algorithm to use. //! //! Supported algorithms: SHA1, SHA2-256, SHA2-512, SHA3-256, SHA3-512, BLAKE, //! BLAKE2, CRC8, CRC16, CRC32, CRC64, MD5, XOR8 //! ``` //! //! -c --create //! //! ```text //! Create directory hashes, rather than verifying them. //! //! Directory hashes are output to the output file, which, if not specified, will //! be "`DIRECTORY`.hash". //! //! Will fail if the output file already exists and `--force` is not specified. //! //! Exclusive with `--verify`. Overrides `--verify`. //! ``` //! //! -v --verify //! //! ```text //! Verify directory hashes. Default. //! //! Exclusive with `--create`. Overrides `--create`. //! ``` //! //! -d --depth <depth> //! //! ```text //! Set max recursion depth to `depth`. Default: 0. //! //! Exclusive with `--recursive`. Overrides `--recursive`. //! ``` //! //! -r --recursive //! //! ```text //! Set max recursion depth to infinity. //! //! Exclusive with `--depth`. Overrides `--depth`. //! ``` //! //! --force //! //! ```text //! Override output file in `--create` mode. No meaning in `--verify` mode. //! ``` //! //! [DIRECTORY] //! //! ```text //! Directory to create/verify hash for. Default: current workdir. //! ``` //! //! ## EXAMPLES //! //! `examples` [`-v`] [`-f` *infile*] //! //! ```text //! Verify the current directory tree against the saved hashes. //! //! `-v` is not necessary as it's the default. //! //! *infile* defaults to "`DIRECTORY`.hash" //! ``` //! //! `examples` `-c` [`-f` *outfile*] [`--force`] //! //! ```text //! Create hashes of the current directory tree for later verification. //! //! *outfile* defaults to "`DIRECTORY`.hash". //! //! Use `--force` to override *outfile*. //! ``` //! //! `examples` [`-d` *depth*] [`-r`] [`OTHER OPTIONS`] //! //! ```text //! Recurse *depth* or infinity directories down. //! ``` extern crate md5; extern crate crc; #[macro_use] extern crate clap; extern crate crc8; extern crate crc16; extern crate blake; extern crate regex; extern crate shaman; extern crate tabwriter; extern crate blake2_rfc; #[macro_use] extern crate lazy_static; extern crate tiny_keccak; mod hashing; mod algorithms; pub mod ops; pub mod util; pub mod options; pub use hashing::hash_file; pub use algorithms::Algorithm; use std::process::exit; use std::io::{stdout, stderr}; fn main() { let result = actual_main(); exit(result); } fn actual_main() -> i32 { let opts = options::Options::parse(); let hashes = ops::create_hashes(&opts.dir, opts.algorithm, opts.depth); if opts.verify { let loaded_hashes = ops::read_hashes(&opts.file.1); let compare_result = ops::compare_hashes(&opts.file.0, hashes, loaded_hashes); ops::write_hash_comparison_results(&mut stdout(), &mut stderr(), compare_result) } else { ops::write_hashes(&opts.file, opts.algorithm, hashes); 0 } }