20 lines
507 B
Rust
20 lines
507 B
Rust
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)
|
|
}
|
|
}
|