style: code style
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -1,14 +1,15 @@
|
||||
#[macro_use]
|
||||
extern crate rust_util;
|
||||
|
||||
mod opt;
|
||||
|
||||
use rust_util::{
|
||||
iff,
|
||||
XResult,
|
||||
new_box_ioerror,
|
||||
util_msg::{ print_message, MessageType, },
|
||||
};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{self, Read, ErrorKind},
|
||||
io::{ self, Read, ErrorKind },
|
||||
};
|
||||
use crypto::{
|
||||
digest::Digest,
|
||||
@@ -21,10 +22,7 @@ use crypto::{
|
||||
sha2::{ Sha224, Sha256, Sha384, Sha512, Sha512Trunc224, Sha512Trunc256, },
|
||||
sha3::Sha3,
|
||||
};
|
||||
use indicatif::{
|
||||
ProgressBar,
|
||||
ProgressStyle
|
||||
};
|
||||
use indicatif::{ ProgressBar, ProgressStyle };
|
||||
use libsm::sm3::hash::Sm3Hash;
|
||||
use opt::Options;
|
||||
|
||||
@@ -40,12 +38,12 @@ fn main() -> XResult<()> {
|
||||
let options = Options::new_and_parse_args()?;
|
||||
|
||||
if options.verbose {
|
||||
print_message(MessageType::DEBUG, &format!("Algorithm: {}", options.algorithm));
|
||||
print_message(MessageType::DEBUG, &format!("Blake len: {}", options.blake_len));
|
||||
debugging!("Algorithm: {}", options.algorithm);
|
||||
debugging!("Blake len: {}", options.blake_len);
|
||||
if !options.file_name_list.is_empty() {
|
||||
print_message(MessageType::DEBUG, "File names:");
|
||||
debugging!("File names:");
|
||||
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),
|
||||
None => match 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 {
|
||||
@@ -71,7 +69,7 @@ fn main() -> XResult<()> {
|
||||
None => match 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(());
|
||||
},
|
||||
},
|
||||
@@ -84,7 +82,7 @@ fn main() -> XResult<()> {
|
||||
|
||||
fn print_version(options: &Options) {
|
||||
println!(r#"digest {} - {}
|
||||
Copyright (C) 2019 Hatter Jiang.
|
||||
Copyright (C) 2019-2020 Hatter Jiang.
|
||||
License MIT <https://opensource.org/licenses/MIT>
|
||||
|
||||
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,
|
||||
SM3, RIPEMD160, WHIRLPOOL, BLAKE2S, BLAKE2B"#, VERSION, &GIT_HASH[0..7]);
|
||||
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