654 lines
19 KiB
Rust
654 lines
19 KiB
Rust
use ascon_hash::{AsconHash256, ExtendableOutput};
|
|
use belt_hash::BeltHash;
|
|
use blake2::{Blake2b512, Blake2s256};
|
|
use blake3::Hasher as Blake3;
|
|
use fsb::{Fsb160, Fsb224, Fsb256, Fsb384, Fsb512};
|
|
use gost94::Gost94CryptoPro;
|
|
use groestl::{Groestl224, Groestl256, Groestl384, Groestl512};
|
|
use jh::{Jh224, Jh256, Jh384, Jh512};
|
|
use k12::KangarooTwelve;
|
|
use md2::Md2;
|
|
use md4::Md4;
|
|
use md5::Md5;
|
|
use ripemd::{Ripemd128, Ripemd160, Ripemd256, Ripemd320};
|
|
use sha1::Sha1;
|
|
use sha2::{Digest as _, Sha224, Sha256, Sha384, Sha512};
|
|
use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shake256};
|
|
use shabal::{Shabal192, Shabal224, Shabal256, Shabal384, Shabal512};
|
|
use skein::{Skein256, Skein512, Skein1024, consts::U32};
|
|
use sm3::Sm3;
|
|
use std::io::{self, Write};
|
|
use std::{fs::File, io::Read};
|
|
use streebog::{Streebog256, Streebog512};
|
|
use tiger::Tiger;
|
|
use whirlpool::Whirlpool;
|
|
|
|
pub fn run_algorithm(algorithm: String, file: Option<File>, stdin: Option<String>) -> String {
|
|
return match &*algorithm.as_str() {
|
|
"ascon" => hash_ascon(file, stdin),
|
|
"belt" => hash_belt(file, stdin),
|
|
"blake2b512" => hash_blake2b512(file, stdin),
|
|
"blake2s256" => hash_blake2s256(file, stdin),
|
|
"blake3" => hash_blake3(file, stdin),
|
|
"fsb160" => hash_fsb160(file, stdin),
|
|
"fsb224" => hash_fsb224(file, stdin),
|
|
"fsb256" => hash_fsb256(file, stdin),
|
|
"fsb384" => hash_fsb384(file, stdin),
|
|
"fsb512" => hash_fsb512(file, stdin),
|
|
"gost94" => hash_gost94(file, stdin),
|
|
"groestl224" => hash_groestl224(file, stdin),
|
|
"groestl256" => hash_groestl256(file, stdin),
|
|
"groestl384" => hash_groestl384(file, stdin),
|
|
"groestl512" => hash_groestl512(file, stdin),
|
|
"jh224" => hash_jh224(file, stdin),
|
|
"jh256" => hash_jh256(file, stdin),
|
|
"jh384" => hash_jh384(file, stdin),
|
|
"jh512" => hash_jh512(file, stdin),
|
|
"k12" => hash_k12(file, stdin),
|
|
"md2" => hash_md2(file, stdin),
|
|
"md4" => hash_md4(file, stdin),
|
|
"md5" => hash_md5(file, stdin),
|
|
"ripemd128" => hash_ripemd128(file, stdin),
|
|
"ripemd160" => hash_ripemd160(file, stdin),
|
|
"ripemd256" => hash_ripemd256(file, stdin),
|
|
"ripemd320" => hash_ripemd320(file, stdin),
|
|
"sha1" => hash_sha1(file, stdin),
|
|
"sha224" => hash_sha224(file, stdin),
|
|
"sha256" => hash_sha256(file, stdin),
|
|
"sha384" => hash_sha384(file, stdin),
|
|
"sha512" => hash_sha512(file, stdin),
|
|
"sha3_224" => hash_sha3_224(file, stdin),
|
|
"sha3_256" => hash_sha3_256(file, stdin),
|
|
"sha3_384" => hash_sha3_384(file, stdin),
|
|
"sha3_512" => hash_sha3_512(file, stdin),
|
|
"shabal192" => hash_shabal192(file, stdin),
|
|
"shabal224" => hash_shabal224(file, stdin),
|
|
"shabal256" => hash_shabal256(file, stdin),
|
|
"shabal384" => hash_shabal384(file, stdin),
|
|
"shabal512" => hash_shabal512(file, stdin),
|
|
"shake128" => hash_shake128(file, stdin),
|
|
"shake256" => hash_shake256(file, stdin),
|
|
"skein256" => hash_skein256(file, stdin),
|
|
"skein512" => hash_skein512(file, stdin),
|
|
"skein1024" => hash_skein1024(file, stdin),
|
|
"sm3" => hash_sm3(file, stdin),
|
|
"streebog256" => hash_streebog256(file, stdin),
|
|
"streebog512" => hash_streebog512(file, stdin),
|
|
"tiger" => hash_tiger(file, stdin),
|
|
"whirlpool" => hash_whirlpool(file, stdin),
|
|
_ => panic!("Somehow did not pass a supported algorithm"),
|
|
};
|
|
}
|
|
|
|
pub fn hash_streebog256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Streebog256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_streebog512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Streebog512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_tiger(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Tiger::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_whirlpool(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Whirlpool::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha224(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha224::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sm3(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sm3::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha3_224(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha3_224::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha3_256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha3_256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha3_384(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha3_384::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha3_512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha3_512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_shake128(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shake128::default();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
_ = hasher.write_fmt(format_args!("{}", stdin.unwrap()));
|
|
}
|
|
|
|
let mut result = String::new();
|
|
let mut finalized = hasher.finalize_xof();
|
|
_ = finalized.read_to_string(&mut result);
|
|
|
|
return format!("{}", result);
|
|
}
|
|
|
|
pub fn hash_shake256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shake256::default();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
_ = hasher.write_fmt(format_args!("{}", stdin.unwrap()));
|
|
}
|
|
|
|
let mut result = String::new();
|
|
let mut finalized = hasher.finalize_xof();
|
|
_ = finalized.read_to_string(&mut result);
|
|
|
|
return format!("{}", result);
|
|
}
|
|
|
|
pub fn hash_shabal192(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shabal192::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_shabal224(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shabal224::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_shabal256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shabal256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_shabal384(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shabal384::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_shabal512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Shabal512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_skein256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Skein256::<U32>::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_skein512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Skein512::<U32>::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_skein1024(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Skein1024::<U32>::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_gost94(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Gost94CryptoPro::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_groestl224(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Groestl224::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_groestl256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Groestl256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_groestl384(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Groestl384::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_groestl512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Groestl512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_jh224(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Jh224::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_jh256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Jh256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_jh384(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Jh384::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_jh512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Jh512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_k12(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = KangarooTwelve::default();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
_ = hasher.write_fmt(format_args!("{}", stdin.unwrap()));
|
|
}
|
|
|
|
let mut result = String::new();
|
|
let mut finalized = hasher.finalize_xof();
|
|
_ = finalized.read_to_string(&mut result);
|
|
|
|
return format!("{}", result);
|
|
}
|
|
|
|
pub fn hash_md2(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Md2::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_md4(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Md4::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_ripemd128(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Ripemd128::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_ripemd160(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Ripemd160::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_ripemd256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Ripemd256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_ripemd320(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Ripemd320::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_ascon(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = AsconHash256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_belt(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = BeltHash::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_blake3(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Blake3::default();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
_ = hasher.write_fmt(format_args!("{}", stdin.unwrap()));
|
|
}
|
|
|
|
return format!("{}", hasher.finalize().to_hex());
|
|
}
|
|
|
|
pub fn hash_blake2b512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Blake2b512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_blake2s256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Blake2s256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_fsb160(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Fsb160::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_fsb224(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Fsb224::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_fsb256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Fsb256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_fsb384(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Fsb384::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_fsb512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Fsb512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_md5(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Md5::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha1(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha1::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha256(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha256::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha384(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha384::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|
|
|
|
pub fn hash_sha512(file: Option<File>, stdin: Option<String>) -> String {
|
|
let mut hasher = Sha512::new();
|
|
if file.is_some() {
|
|
_ = io::copy(&mut file.unwrap(), &mut hasher);
|
|
} else if stdin.is_some() {
|
|
hasher.update(stdin.unwrap());
|
|
}
|
|
|
|
return format!("{:x}", hasher.finalize());
|
|
}
|