hash: hash crate for all hashing needs, password

This commit is contained in:
Philippe Loctaux 2023-03-05 23:28:14 +01:00
parent 7851fdae1e
commit 8af226cd05
5 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,20 @@
use crate::error::Error;
use crate::hash::{hash, Hash};
#[derive(Debug)]
pub struct Password(Hash);
impl Password {
pub fn new(plain: &str) -> Result<Self, Error> {
Ok(Self(Hash::from_hash(hash(plain)?)))
}
pub fn from_hash(hash: impl Into<String>) -> Self {
Self(Hash::from_hash(hash))
}
pub fn hash(&self) -> &str {
self.0.hash()
}
pub fn compare(&self, plain: &str) -> Result<bool, Error> {
self.0.compare(plain).map_err(Error::from)
}
}