vtse/vtse-server/src/user.rs

26 lines
662 B
Rust

use sodiumoxide::crypto::pwhash::argon2id13::HashedPassword;
use sodiumoxide::crypto::pwhash::argon2id13::{pwhash, MEMLIMIT_INTERACTIVE, OPSLIMIT_INTERACTIVE};
use std::convert::TryFrom;
use vtse_common::user::Password;
pub(crate) struct SaltedPassword(HashedPassword);
impl TryFrom<Password> for SaltedPassword {
type Error = ();
fn try_from(password: Password) -> Result<Self, Self::Error> {
pwhash(
password.as_bytes(),
OPSLIMIT_INTERACTIVE,
MEMLIMIT_INTERACTIVE,
)
.map(Self)
}
}
impl AsRef<[u8]> for SaltedPassword {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}