Enable descriptive HTTP errors to be returned from DB layer

For now, we only use this when redeeming an invite code.

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo 2022-05-19 11:55:55 -06:00
parent d1b7a249b4
commit 3d7e912c6b
5 changed files with 45 additions and 7 deletions

View file

@ -91,7 +91,8 @@ fn hash_access_token(token: &str) -> Result<String> {
None,
params,
&SaltString::generate(thread_rng()),
)?
)
.map_err(anyhow::Error::new)?
.to_string())
}
@ -105,6 +106,6 @@ pub fn encrypt_access_token(access_token: &str, public_key: String) -> Result<St
}
pub fn verify_access_token(token: &str, hash: &str) -> Result<bool> {
let hash = PasswordHash::new(hash)?;
let hash = PasswordHash::new(hash).map_err(anyhow::Error::new)?;
Ok(Scrypt.verify_password(token.as_bytes(), &hash).is_ok())
}