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