password_worker/hasher_impls/
bcrypt.rs1use crate::{Hasher, PasswordWorker, PasswordWorkerError};
2
3#[derive(Clone, Copy, Debug)]
5pub enum Bcrypt {}
6
7impl Hasher for Bcrypt {
8 type Config = BcryptConfig;
9 type Error = bcrypt::BcryptError;
10
11 fn hash(data: impl AsRef<[u8]>, config: &Self::Config) -> Result<String, Self::Error> {
12 bcrypt::hash(data, config.cost)
13 }
14
15 fn verify(data: impl AsRef<[u8]>, hash: &str) -> Result<bool, Self::Error> {
16 bcrypt::verify(data, hash)
17 }
18}
19
20#[derive(Clone, Copy)]
22pub struct BcryptConfig {
23 pub cost: u32,
25}
26
27impl PasswordWorker<Bcrypt> {
28 pub fn new_bcrypt(max_threads: usize) -> Result<Self, PasswordWorkerError<Bcrypt>> {
30 PasswordWorker::<Bcrypt>::new(max_threads)
31 }
32}