From bcb903c0aff298bc15ddde8445976d1252762c75 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 7 Dec 2022 19:29:44 +0000 Subject: [PATCH] Ensure functions are in alphabetical order --- lib/src/fnc/crypto.rs | 62 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/src/fnc/crypto.rs b/lib/src/fnc/crypto.rs index abd4d50e..a554eec6 100644 --- a/lib/src/fnc/crypto.rs +++ b/lib/src/fnc/crypto.rs @@ -111,6 +111,37 @@ pub mod argon2 { } } +pub mod bcrypt { + + use crate::err::Error; + use crate::fnc::crypto::COST_ALLOWANCE; + use crate::sql::value::Value; + use bcrypt; + use bcrypt::HashParts; + use std::str::FromStr; + + pub fn cmp((hash, pass): (String, String)) -> Result { + let parts = match HashParts::from_str(&hash) { + Ok(parts) => parts, + Err(_) => return Ok(Value::False), + }; + // Note: Bcrypt cost is exponential, so add the cost allowance as opposed to multiplying. + Ok(if parts.get_cost() > bcrypt::DEFAULT_COST.saturating_add(COST_ALLOWANCE) { + // Too expensive to compute. + Value::False + } else { + // FIXME: If base64 dependency is added, can avoid parsing the HashParts twice, once + // above and once in verity, by using bcrypt::bcrypt. + bcrypt::verify(pass, &hash).unwrap_or(false).into() + }) + } + + pub fn gen((pass,): (String,)) -> Result { + let hash = bcrypt::hash(pass, bcrypt::DEFAULT_COST).unwrap(); + Ok(hash.into()) + } +} + pub mod pbkdf2 { use super::COST_ALLOWANCE; @@ -180,34 +211,3 @@ pub mod scrypt { Ok(hash.into()) } } - -pub mod bcrypt { - - use crate::err::Error; - use crate::fnc::crypto::COST_ALLOWANCE; - use crate::sql::value::Value; - use bcrypt; - use bcrypt::HashParts; - use std::str::FromStr; - - pub fn cmp((hash, pass): (String, String)) -> Result { - let parts = match HashParts::from_str(&hash) { - Ok(parts) => parts, - Err(_) => return Ok(Value::False), - }; - // Note: Bcrypt cost is exponential, so add the cost allowance as opposed to multiplying. - Ok(if parts.get_cost() > bcrypt::DEFAULT_COST.saturating_add(COST_ALLOWANCE) { - // Too expensive to compute. - Value::False - } else { - // FIXME: If base64 dependency is added, can avoid parsing the HashParts twice, once - // above and once in verity, by using bcrypt::bcrypt. - bcrypt::verify(pass, &hash).unwrap_or(false).into() - }) - } - - pub fn gen((pass,): (String,)) -> Result { - let hash = bcrypt::hash(pass, bcrypt::DEFAULT_COST).unwrap(); - Ok(hash.into()) - } -}