Skip to content

Commit

Permalink
Several small changes (#65)
Browse files Browse the repository at this point in the history
* Modified the pbkdf2 hash function

* Modified the algo check for file ops

* Added the nonsupported algos

* Changed version

* Deleted github actions
  • Loading branch information
vschwaberow authored Dec 11, 2022
1 parent ae4aee7 commit de6a97b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 180 deletions.
151 changes: 0 additions & 151 deletions .github/workflows/rust.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustgenhash"
version = "0.5.13"
version = "0.5.14"
license = "MIT"
authors = ["Volker Schwaberow <[email protected]>"]
description = "A tool to generate hashes from the command line."
Expand Down
44 changes: 25 additions & 19 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ pub enum Algorithm {
Whirlpool,
}

struct AlgorithmProperties {
file_support: bool,
}

impl Algorithm {
fn properties(&self) -> AlgorithmProperties {
match *self {
Algorithm::Argon2 => AlgorithmProperties { file_support: false },
Algorithm::Pbkdf2Sha256 | Algorithm::Pbkdf2Sha512 => {
AlgorithmProperties { file_support: false }
},
Algorithm::Scrypt => AlgorithmProperties { file_support: false },
Algorithm::Shacrypt => AlgorithmProperties { file_support: false },
Algorithm::Bcrypt => AlgorithmProperties { file_support: false },
Algorithm::Balloon => AlgorithmProperties { file_support: false },
_ => AlgorithmProperties { file_support: true }
}
}
}

fn hash_string(
algor: Algorithm,
password: &str,
Expand Down Expand Up @@ -135,26 +155,12 @@ fn hash_string(
}

fn hash_file(alg: Algorithm, input: &str, option: OutputOptions) {
use Algorithm as algo;
match alg {
algo::Argon2
| algo::Balloon
| algo::Bcrypt
| algo::Pbkdf2Sha256
| algo::Pbkdf2Sha512
| algo::Scrypt
| algo::Shacrypt => {
println!(
"{:?} is not supported for files",
format!("{:?}", alg).to_lowercase().as_str()
);
std::process::exit(1);
}
_ => {
let alg_s = format!("{:?}", alg).to_uppercase();
RHash::new(&alg_s).process_file(input, option);
}
if !alg.properties().file_support {
println!("Algorithm {:?} does not support file hashing", alg);
std::process::exit(1);
}
let alg_s = format!("{:?}", alg).to_uppercase();
RHash::new(&alg_s).process_file(input, option);
}

fn build_cli() -> clap::Command {
Expand Down
20 changes: 12 additions & 8 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use pbkdf2::{
password_hash::{Ident as PbIdent, SaltString as PbSaltString},
Pbkdf2,
};
use std::io::Read;
use std::{io::Read, collections::HashMap};

use scrypt::{password_hash::SaltString as ScSaltString, Scrypt};

Expand Down Expand Up @@ -95,12 +95,12 @@ impl PHash {
}

pub fn hash_pbkdf2(password: &str, pb_scheme: &str) {
let pb_s = match pb_scheme {
"pbkdf2sha256" => "pbkdf2-sha256",
"pbkdf2sha512" => "pbkdf2-sha512",
_ => "NONE",
};
let pb_scheme_hmap: HashMap<&str, &str> = [
("pbkdf2sha256", "pbkdf2-sha256"),
("pbkdf2sha512", "pbkdf2-sha512")
].iter().cloned().collect();

let pb_s = pb_scheme_hmap.get(pb_scheme).unwrap_or(&"NONE");
let algorithm = PbIdent::new(pb_s).unwrap();
let salt = PbSaltString::generate(&mut OsRng);
let params = pbkdf2::Params {
Expand All @@ -115,11 +115,15 @@ impl PHash {
params,
salt.as_salt(),
)
.unwrap()
.to_string();
.unwrap_or_else(|_| {
eprintln!("Error: {}", "Could not hash PBKDF2 password");
std::process::exit(1);
});
println!("{} {}", password_hash, password);

}


pub fn hash_scrypt(password: &str) {
let salt = ScSaltString::generate(&mut OsRng);
let password_hash = Scrypt
Expand Down

0 comments on commit de6a97b

Please sign in to comment.