ref str
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -55,24 +55,21 @@ fn main() -> XResult<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let the_algo = options.algorithm.to_uppercase();
|
let the_algo: &str = &options.algorithm.to_uppercase();
|
||||||
if options.file_name_list.is_empty() {
|
if options.file_name_list.is_empty() {
|
||||||
let boxed_digest = get_digest_by_algorithm(the_algo.as_str(), &options);
|
match get_digest_by_algorithm(the_algo, &options) {
|
||||||
match boxed_digest {
|
|
||||||
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.as_str() {
|
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)),
|
_ => print_message(MessageType::ERROR, &format!("Unknown algorithm: {}", options.algorithm)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
for f in &options.file_name_list {
|
for file in &options.file_name_list {
|
||||||
let the_fn = f.as_str();
|
match get_digest_by_algorithm(the_algo, &options) {
|
||||||
let boxed_digest = get_digest_by_algorithm(the_algo.as_str(), &options);
|
Some(mut digest) => println!("{} - {} ({})", calc_file_digest(&mut *digest, file)?, file, the_algo),
|
||||||
match boxed_digest {
|
None => match the_algo {
|
||||||
Some(mut digest) => println!("{} - {} ({})", calc_file_digest(&mut *digest, the_fn)?, the_fn, the_algo),
|
"SM3" => println!("{} - {} ({})", hex::encode(Sm3Hash::new(&read_file_full(file)?).get_hash()), file, the_algo),
|
||||||
None => match the_algo.as_str() {
|
|
||||||
"SM3" => println!("{} - {} ({})", hex::encode(Sm3Hash::new(&read_file_full(the_fn)?).get_hash()), the_fn, the_algo),
|
|
||||||
_ => {
|
_ => {
|
||||||
print_message(MessageType::ERROR, &format!("Unknown algorithm: {}", options.algorithm));
|
print_message(MessageType::ERROR, &format!("Unknown algorithm: {}", options.algorithm));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
Reference in New Issue
Block a user