use crypt_io::kdf;
fn main() -> Result<(), crypt_io::Error> {
let user_password = b"correct horse battery staple";
let phc_string = kdf::argon2_hash(user_password)?;
println!("Hash: {phc_string}");
let supplied_correct = b"correct horse battery staple";
let supplied_wrong = b"hunter2";
let ok = kdf::argon2_verify(&phc_string, supplied_correct)?;
println!("Correct password verifies: {ok}");
assert!(ok);
let ok = kdf::argon2_verify(&phc_string, supplied_wrong)?;
println!("Wrong password verifies: {ok}");
assert!(!ok);
match kdf::argon2_verify("definitely not a phc string", user_password) {
Ok(_) => unreachable!("malformed PHC shouldn't parse"),
Err(e) => println!("Malformed PHC: {e}"),
}
use crypt_io::kdf::{Argon2Params, argon2_hash_with_params};
let strong = Argon2Params {
m_cost: 64 * 1024, t_cost: 3,
p_cost: 1,
output_len: 32,
};
let phc = argon2_hash_with_params(b"service-token", strong)?;
assert!(kdf::argon2_verify(&phc, b"service-token")?);
println!("Custom-params hash verified.");
Ok(())
}