hash: hash crate for all hashing needs, password
This commit is contained in:
parent
7851fdae1e
commit
8af226cd05
5 changed files with 128 additions and 0 deletions
20
crates/hash/src/password.rs
Normal file
20
crates/hash/src/password.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue