aboutsummaryrefslogtreecommitdiffstats
path: root/src/auth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/auth.rs b/src/auth.rs
index 8e6532b..c786d4b 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -3,7 +3,7 @@ use actix_web::middleware::{Middleware, Response};
use actix_web::{HttpRequest, HttpResponse, Result};
use sha2::{Digest, Sha256, Sha512};
-use crate::errors::{ContextualError};
+use crate::errors::ContextualError;
pub struct Auth;
@@ -36,10 +36,7 @@ pub fn parse_basic_auth(
let basic_removed = authorization_header
.to_str()
.map_err(|e| {
- ContextualError::ParseError(
- "HTTP authentication header".to_string(),
- e.to_string(),
- )
+ ContextualError::ParseError("HTTP authentication header".to_string(), e.to_string())
})?
.replace("Basic ", "");
let decoded = base64::decode(&basic_removed).map_err(ContextualError::Base64DecodeError)?;
@@ -75,8 +72,8 @@ pub fn match_auth(basic_auth: BasicAuthParams, required_auth: &RequiredAuth) ->
}
/// Return `true` if hashing of `password` by `T` algorithm equals to `hash`
-pub fn compare_hash<T: Digest>(password: String, hash: &Vec<u8>) -> bool {
- get_hash::<T>(password) == *hash
+pub fn compare_hash<T: Digest>(password: String, hash: &[u8]) -> bool {
+ get_hash::<T>(password) == hash
}
/// Get hash of a `text`
@@ -163,13 +160,18 @@ mod tests {
}
#[rstest_parametrize(
- should_pass, param_username, param_password, required_username, required_password, encrypt,
+ should_pass,
+ param_username,
+ param_password,
+ required_username,
+ required_password,
+ encrypt,
case(true, "obi", "hello there", "obi", "hello there", "plain"),
case(false, "obi", "hello there", "obi", "hi!", "plain"),
case(true, "obi", "hello there", "obi", "hello there", "sha256"),
case(false, "obi", "hello there", "obi", "hi!", "sha256"),
case(true, "obi", "hello there", "obi", "hello there", "sha512"),
- case(false, "obi", "hello there", "obi", "hi!", "sha512"),
+ case(false, "obi", "hello there", "obi", "hi!", "sha512")
)]
fn test_auth(
should_pass: bool,