#![allow(clippy::unwrap_used, clippy::expect_used)]
use hsh::policy::{Policy, PolicyBuilder, PrimaryAlgorithm};
use hsh::{api, Outcome};
fn main() {
let bcrypt_policy =
PolicyBuilder::from_preset(&Policy::owasp_minimum_2025())
.primary(PrimaryAlgorithm::Bcrypt)
.build()
.unwrap();
let legacy_bcrypt =
api::hash(&bcrypt_policy, "user-password").unwrap();
println!("legacy bcrypt: {legacy_bcrypt}");
let new_policy = Policy::owasp_minimum_2025(); let outcome = api::verify_and_upgrade(
&new_policy,
"user-password",
&legacy_bcrypt,
)
.unwrap();
assert!(matches!(outcome, Outcome::Valid { rehashed: Some(_) }));
let upgraded = outcome
.rehashed()
.expect("needs_rehash → new PHC")
.to_owned();
assert!(upgraded.starts_with("$argon2id$"));
println!("upgraded : {upgraded}");
}