main: add hash command
This commit is contained in:
parent
08cd2e4ec6
commit
026797d935
13
src/main.rs
13
src/main.rs
|
@ -52,11 +52,17 @@ fn main() {
|
|||
.takes_value(true)
|
||||
.required(false)
|
||||
.default_value(default_namefilepath)))
|
||||
.subcommand(SubCommand::with_name("hash")
|
||||
.about("Calculate hash for a string")
|
||||
.arg(Arg::with_name("value")
|
||||
.takes_value(true)
|
||||
.required(true)))
|
||||
.get_matches();
|
||||
|
||||
process::exit(match matches.subcommand() {
|
||||
("bhd", Some(s)) => { cmd_bhd(s) }
|
||||
("bhds", Some(s)) => { cmd_bhds(s) }
|
||||
("hash", Some(s)) => { cmd_hash(s) }
|
||||
_ => { 0 }
|
||||
})
|
||||
}
|
||||
|
@ -113,6 +119,7 @@ fn cmd_bhds(args: &ArgMatches) -> i32 {
|
|||
bhd_paths.sort();
|
||||
|
||||
for bhd_path in bhd_paths {
|
||||
println!("Extracting {:?}", bhd_path);
|
||||
match unpackers::bhd::extract_bhd(bhd_path.to_str().unwrap(), &names, output_path) {
|
||||
Err(e) => { eprintln!("Failed to extract BHD: {:?}", e); return 1 }
|
||||
_ => {}
|
||||
|
@ -120,3 +127,9 @@ fn cmd_bhds(args: &ArgMatches) -> i32 {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
fn cmd_hash(args: &ArgMatches) -> i32 {
|
||||
let value: &str = args.value_of("value").unwrap();
|
||||
println!("{}", name_hashes::hash_as_string(name_hashes::hash(&value)));
|
||||
0
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use num_bigint::BigUint;
|
|||
use num_traits::identities::Zero;
|
||||
|
||||
/// Compute the weird hash for a string. Same mechanic since DeS.
|
||||
#[allow(dead_code)]
|
||||
pub fn hash(s: &str) -> u32 {
|
||||
let s = s.to_lowercase();
|
||||
let mut val = BigUint::zero();
|
||||
|
|
Reference in a new issue