use crate::models::hash_algorithm::HashingAlgorithm;
use scrypt::scrypt;
use scrypt::Params;
use serde::{Deserialize, Serialize};
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
Serialize,
Deserialize,
)]
pub struct Scrypt;
impl HashingAlgorithm for Scrypt {
fn hash_password(
password: &str,
salt: &str,
) -> Result<Vec<u8>, String> {
let params =
Params::new(14, 8, 1, 64).map_err(|e| e.to_string())?;
let mut output = [0u8; 64];
scrypt(
password.as_bytes(),
salt.as_bytes(),
¶ms,
&mut output,
)
.map_err(|e| e.to_string())
.map(|_| output.to_vec())
}
}