use rust_util 0.2.2
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)",
|
||||
"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_util 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rust_util 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -446,7 +446,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rust_util"
|
||||
version = "0.1.0"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"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 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_util 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5dc9b9d45cf4e9a8a28c1c622f0a2bba9af88b85ec04c494d80605a717c1c022"
|
||||
"checksum rust_util 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd9973675144c03fdf6f9a559ea5c254b0008e90a8992b1f317f728edd3512bc"
|
||||
"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 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"
|
||||
hex = "0.4.0"
|
||||
indicatif = "0.13.0"
|
||||
rust_util = "0.1.0"
|
||||
rust_util = "0.2.2"
|
||||
|
||||
|
||||
|
||||
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