use rust_util 0.2.2
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -1,12 +1,10 @@
|
||||
mod opt;
|
||||
|
||||
use rust_util::{
|
||||
iff,
|
||||
XResult,
|
||||
new_box_ioerror,
|
||||
util_msg::{
|
||||
print_message,
|
||||
MessageType,
|
||||
},
|
||||
util_msg::{ print_message, MessageType, },
|
||||
};
|
||||
use std::{
|
||||
fs::File,
|
||||
@@ -20,14 +18,7 @@ use crypto::{
|
||||
blake2b::Blake2b,
|
||||
md5::Md5,
|
||||
sha1::Sha1,
|
||||
sha2::{
|
||||
Sha224,
|
||||
Sha256,
|
||||
Sha384,
|
||||
Sha512,
|
||||
Sha512Trunc224,
|
||||
Sha512Trunc256,
|
||||
},
|
||||
sha2::{ Sha224, Sha256, Sha384, Sha512, Sha512Trunc224, Sha512Trunc256, },
|
||||
sha3::Sha3,
|
||||
};
|
||||
use indicatif::{
|
||||
@@ -115,8 +106,8 @@ fn get_digest_by_algorithm(algo: &str, options: &Options) -> Option<Box<dyn Dige
|
||||
match algo {
|
||||
"RIPEMD160" => Some(Box::new(Ripemd160::new())),
|
||||
"WHIRLPOOL" => Some(Box::new(Whirlpool::new())),
|
||||
"BLAKE2S" => Some(Box::new(Blake2s::new(if options.blake_len == 0_usize { 32 } else { options.blake_len }))),
|
||||
"BLAKE2B" => Some(Box::new(Blake2b::new(if options.blake_len == 0_usize { 64 } else { options.blake_len }))),
|
||||
"BLAKE2S" => Some(Box::new(Blake2s::new(iff!(options.blake_len == 0_usize, 32, options.blake_len)))),
|
||||
"BLAKE2B" => Some(Box::new(Blake2b::new(iff!(options.blake_len == 0_usize, 64, options.blake_len)))),
|
||||
"MD5" => Some(Box::new(Md5::new())),
|
||||
"SHA1" | "SHA-1" => Some(Box::new(Sha1::new())),
|
||||
"SHA224" | "SHA-224" => Some(Box::new(Sha224::new())),
|
||||
@@ -143,16 +134,17 @@ fn read_file_full(file_name: &str) -> XResult<Vec<u8>> {
|
||||
let mut buf: [u8; BUFF_SIZE] = [0u8; BUFF_SIZE];
|
||||
let mut f = File::open(file_name)?;
|
||||
let file_len = f.metadata()?.len();
|
||||
let mut ret: Vec<u8> = Vec::new();
|
||||
let mut read = 0_u64;
|
||||
|
||||
if file_len > FILE_SIZE_1GB {
|
||||
return Err(new_box_ioerror("File too large!"));
|
||||
return Err(new_box_ioerror(&format!("File too large!, file size: {}bytes", file_len)));
|
||||
}
|
||||
|
||||
let mut ret: Vec<u8> = Vec::with_capacity(file_len as usize);
|
||||
|
||||
let pb = ProgressBar::new(file_len);
|
||||
pb.set_style(ProgressStyle::default_bar().template(PB_TEMPLATE).progress_chars(PB_PROGRESS));
|
||||
|
||||
let mut read = 0_u64;
|
||||
loop {
|
||||
let len = match f.read(&mut buf) {
|
||||
Ok(0) => { pb.finish_and_clear(); return Ok(ret); },
|
||||
@@ -195,7 +187,7 @@ fn read_full_stdin() -> XResult<Vec<u8>> {
|
||||
let mut handle = stdin.lock();
|
||||
loop {
|
||||
let len = match handle.read(&mut buf) {
|
||||
Ok(0) => { return Ok(ret); },
|
||||
Ok(0) => return Ok(ret),
|
||||
Ok(len) => len,
|
||||
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
|
||||
Err(e) => return Err(Box::new(e)),
|
||||
@@ -210,7 +202,7 @@ fn calc_digest_stdin(digest: &mut dyn Digest) -> XResult<String> {
|
||||
let mut handle = stdin.lock();
|
||||
loop {
|
||||
let len = match handle.read(&mut buf) {
|
||||
Ok(0) => { return Ok(digest.result_str()); },
|
||||
Ok(0) => return Ok(digest.result_str()),
|
||||
Ok(len) => len,
|
||||
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
|
||||
Err(e) => return Err(Box::new(e)),
|
||||
|
||||
Reference in New Issue
Block a user