use crate::{Hasher, PasswordWorker, PasswordWorkerError};
#[derive(Clone, Copy, Debug)]
pub enum Bcrypt {}
impl Hasher for Bcrypt {
type Config = BcryptConfig;
type Error = bcrypt::BcryptError;
fn hash(data: impl AsRef<[u8]>, config: &Self::Config) -> Result<String, Self::Error> {
bcrypt::hash(data, config.cost)
}
fn verify(data: impl AsRef<[u8]>, hash: &str) -> Result<bool, Self::Error> {
bcrypt::verify(data, hash)
}
}
#[derive(Clone, Copy)]
pub struct BcryptConfig {
pub cost: u32,
}
#[cfg_attr(docsrs, doc(cfg(feature = "bcrypt")))]
impl PasswordWorker<Bcrypt> {
pub fn new_bcrypt(max_threads: usize) -> Result<Self, PasswordWorkerError<Bcrypt>> {
PasswordWorker::<Bcrypt>::new(max_threads)
}
}