style: code style
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -149,7 +149,7 @@ dependencies = [
|
|||||||
"indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libsm 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libsm 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rust_util 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rust_util 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -446,7 +446,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.2.2"
|
version = "0.6.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -626,7 +626,7 @@ dependencies = [
|
|||||||
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
|
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
|
||||||
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
|
"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
|
||||||
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
|
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
|
||||||
"checksum rust_util 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd9973675144c03fdf6f9a559ea5c254b0008e90a8992b1f317f728edd3512bc"
|
"checksum rust_util 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9e9cf201657d8553fd7eddf4c20e00b1bdebca40e9fa2ede5c87f6874d02750f"
|
||||||
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
|
||||||
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
||||||
"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92"
|
"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92"
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ libsm = "0.3.0"
|
|||||||
rust-crypto = "0.2.36"
|
rust-crypto = "0.2.36"
|
||||||
hex = "0.4.0"
|
hex = "0.4.0"
|
||||||
indicatif = "0.13.0"
|
indicatif = "0.13.0"
|
||||||
rust_util = "0.2.2"
|
rust_util = "0.6.3"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
28
src/main.rs
28
src/main.rs
@@ -1,14 +1,15 @@
|
|||||||
|
#[macro_use]
|
||||||
|
extern crate rust_util;
|
||||||
|
|
||||||
mod opt;
|
mod opt;
|
||||||
|
|
||||||
use rust_util::{
|
use rust_util::{
|
||||||
iff,
|
|
||||||
XResult,
|
XResult,
|
||||||
new_box_ioerror,
|
new_box_ioerror,
|
||||||
util_msg::{ print_message, MessageType, },
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, Read, ErrorKind},
|
io::{ self, Read, ErrorKind },
|
||||||
};
|
};
|
||||||
use crypto::{
|
use crypto::{
|
||||||
digest::Digest,
|
digest::Digest,
|
||||||
@@ -21,10 +22,7 @@ use crypto::{
|
|||||||
sha2::{ Sha224, Sha256, Sha384, Sha512, Sha512Trunc224, Sha512Trunc256, },
|
sha2::{ Sha224, Sha256, Sha384, Sha512, Sha512Trunc224, Sha512Trunc256, },
|
||||||
sha3::Sha3,
|
sha3::Sha3,
|
||||||
};
|
};
|
||||||
use indicatif::{
|
use indicatif::{ ProgressBar, ProgressStyle };
|
||||||
ProgressBar,
|
|
||||||
ProgressStyle
|
|
||||||
};
|
|
||||||
use libsm::sm3::hash::Sm3Hash;
|
use libsm::sm3::hash::Sm3Hash;
|
||||||
use opt::Options;
|
use opt::Options;
|
||||||
|
|
||||||
@@ -40,12 +38,12 @@ fn main() -> XResult<()> {
|
|||||||
let options = Options::new_and_parse_args()?;
|
let options = Options::new_and_parse_args()?;
|
||||||
|
|
||||||
if options.verbose {
|
if options.verbose {
|
||||||
print_message(MessageType::DEBUG, &format!("Algorithm: {}", options.algorithm));
|
debugging!("Algorithm: {}", options.algorithm);
|
||||||
print_message(MessageType::DEBUG, &format!("Blake len: {}", options.blake_len));
|
debugging!("Blake len: {}", options.blake_len);
|
||||||
if !options.file_name_list.is_empty() {
|
if !options.file_name_list.is_empty() {
|
||||||
print_message(MessageType::DEBUG, "File names:");
|
debugging!("File names:");
|
||||||
for f in &options.file_name_list {
|
for f in &options.file_name_list {
|
||||||
print_message(MessageType::DEBUG, &format!("- {}", f.as_str()));
|
debugging!("- {}", f.as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +59,7 @@ fn main() -> XResult<()> {
|
|||||||
Some(mut digest) => println!("{} - ({})", calc_digest_stdin(&mut *digest)?, the_algo),
|
Some(mut digest) => println!("{} - ({})", calc_digest_stdin(&mut *digest)?, the_algo),
|
||||||
None => match the_algo {
|
None => match the_algo {
|
||||||
"SM3" => println!("{} - ({})", hex::encode(Sm3Hash::new(&read_full_stdin()?).get_hash()), the_algo),
|
"SM3" => println!("{} - ({})", hex::encode(Sm3Hash::new(&read_full_stdin()?).get_hash()), the_algo),
|
||||||
_ => print_message(MessageType::ERROR, &format!("Unknown algorithm: {}", options.algorithm)),
|
_ => failure!("Unknown algorithm: {}", options.algorithm),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -71,7 +69,7 @@ fn main() -> XResult<()> {
|
|||||||
None => match the_algo {
|
None => match the_algo {
|
||||||
"SM3" => println!("{} - {} ({})", hex::encode(Sm3Hash::new(&read_file_full(file)?).get_hash()), file, the_algo),
|
"SM3" => println!("{} - {} ({})", hex::encode(Sm3Hash::new(&read_file_full(file)?).get_hash()), file, the_algo),
|
||||||
_ => {
|
_ => {
|
||||||
print_message(MessageType::ERROR, &format!("Unknown algorithm: {}", options.algorithm));
|
failure!("Unknown algorithm: {}", options.algorithm);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -84,7 +82,7 @@ fn main() -> XResult<()> {
|
|||||||
|
|
||||||
fn print_version(options: &Options) {
|
fn print_version(options: &Options) {
|
||||||
println!(r#"digest {} - {}
|
println!(r#"digest {} - {}
|
||||||
Copyright (C) 2019 Hatter Jiang.
|
Copyright (C) 2019-2020 Hatter Jiang.
|
||||||
License MIT <https://opensource.org/licenses/MIT>
|
License MIT <https://opensource.org/licenses/MIT>
|
||||||
|
|
||||||
Written by Hatter Jiang
|
Written by Hatter Jiang
|
||||||
@@ -95,7 +93,7 @@ SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE-128, SHAKE-256,
|
|||||||
KECCAK-224, KECCAK-256, KECCAK-384, KECCAK-512,
|
KECCAK-224, KECCAK-256, KECCAK-384, KECCAK-512,
|
||||||
SM3, RIPEMD160, WHIRLPOOL, BLAKE2S, BLAKE2B"#, VERSION, &GIT_HASH[0..7]);
|
SM3, RIPEMD160, WHIRLPOOL, BLAKE2S, BLAKE2B"#, VERSION, &GIT_HASH[0..7]);
|
||||||
if options.verbose {
|
if options.verbose {
|
||||||
print_message(MessageType::DEBUG, &format!("Full git hash: {}", &GIT_HASH));
|
debugging!("Full git hash: {}", &GIT_HASH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user