diff options
author | khai96_ <hvksmr1996@gmail.com> | 2019-04-24 12:03:48 +0000 |
---|---|---|
committer | khai96_ <hvksmr1996@gmail.com> | 2019-04-24 12:03:48 +0000 |
commit | 706649e38b850f6210dbface1a6c0ca5ccdb468f (patch) | |
tree | 6b4f99730c3579b6cf855bdb30c267bb4ca4ecce | |
parent | Use format! instead of manual string concatenation (diff) | |
download | miniserve-706649e38b850f6210dbface1a6c0ca5ccdb468f.tar.gz miniserve-706649e38b850f6210dbface1a6c0ca5ccdb468f.zip |
Run cargo fmt
-rw-r--r-- | src/args.rs | 4 | ||||
-rw-r--r-- | src/auth.rs | 16 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/args.rs b/src/args.rs index b7e31b0..f13d14f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -161,7 +161,7 @@ pub fn parse_args() -> crate::MiniserveConfig { mod tests { use super::*; - fn create_required_auth (username: &str, password: &str, encrypt: &str) -> auth::RequiredAuth { + fn create_required_auth(username: &str, password: &str, encrypt: &str) -> auth::RequiredAuth { use auth::*; use RequiredAuthPassword::*; @@ -171,7 +171,7 @@ mod tests { "plain" => Plain(password.to_owned()), "sha256" => Sha256(hex::decode(password.to_owned()).unwrap()), "sha512" => Sha512(hex::decode(password.to_owned()).unwrap()), - _ => panic!("Unknown encryption type") + _ => panic!("Unknown encryption type"), }, } } diff --git a/src/auth.rs b/src/auth.rs index 806bdb7..a4b3555 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,7 +1,7 @@ use actix_web::http::header; use actix_web::middleware::{Middleware, Response}; use actix_web::{HttpRequest, HttpResponse, Result}; -use sha2::{Sha256, Sha512, Digest}; +use sha2::{Digest, Sha256, Sha512}; pub struct Auth; @@ -55,9 +55,15 @@ pub fn match_auth(basic_auth: BasicAuthParams, required_auth: &RequiredAuth) -> } match &required_auth.password { - RequiredAuthPassword::Plain(ref required_password) => basic_auth.password == *required_password, - RequiredAuthPassword::Sha256(password_hash) => compare_hash::<Sha256>(basic_auth.password, password_hash), - RequiredAuthPassword::Sha512(password_hash) => compare_hash::<Sha512>(basic_auth.password, password_hash), + RequiredAuthPassword::Plain(ref required_password) => { + basic_auth.password == *required_password + } + RequiredAuthPassword::Sha256(password_hash) => { + compare_hash::<Sha256>(basic_auth.password, password_hash) + } + RequiredAuthPassword::Sha512(password_hash) => { + compare_hash::<Sha512>(basic_auth.password, password_hash) + } } } @@ -145,7 +151,7 @@ mod tests { "plain" => Plain(password.to_owned()), "sha256" => Sha256(get_hash::<sha2::Sha256>(password.to_owned())), "sha512" => Sha512(get_hash::<sha2::Sha512>(password.to_owned())), - _ => panic!("Unknown encryption type") + _ => panic!("Unknown encryption type"), }, } } |