aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkhai96_ <hvksmr1996@gmail.com>2019-04-19 15:44:31 +0000
committerkhai96_ <hvksmr1996@gmail.com>2019-04-19 15:44:31 +0000
commit8a548fd1eba41ecca91928b855eb4241352ba1d8 (patch)
treefaf0010885bae6266d1a57cbe0fcd8bee3aa0890 /src
parentFix parse_auth and add some tests (diff)
downloadminiserve-8a548fd1eba41ecca91928b855eb4241352ba1d8.tar.gz
miniserve-8a548fd1eba41ecca91928b855eb4241352ba1d8.zip
Resolve https://github.com/svenstaro/miniserve/pull/76#discussion_r277011948
Diffstat (limited to 'src')
-rw-r--r--src/args.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/args.rs b/src/args.rs
index c7a4917..d26fb41 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -91,22 +91,21 @@ fn parse_auth(src: &str) -> Result<auth::RequiredAuth, String> {
None => return Err(errmsg),
};
- let password = match split.next() {
- Some(hash) => match second_part {
+ let password = if let Some(hash) = split.next() {
+ match second_part {
"sha256" => auth::RequiredAuthPassword::Sha256(hash.to_owned()),
"sha512" => auth::RequiredAuthPassword::Sha512(hash.to_owned()),
_ => return Err("Invalid hash method, valid methods is sha256".to_owned())
- },
- None => {
- // To make it Windows-compatible, the password needs to be shorter than 255 characters.
- // After 255 characters, Windows will truncate the value.
- // As for the username, the spec does not mention a limit in length
- if second_part.len() > 255 {
- return Err("Password length cannot exceed 255 characters".to_owned());
- }
-
- auth::RequiredAuthPassword::Plain(second_part.to_owned())
- },
+ }
+ } else {
+ // To make it Windows-compatible, the password needs to be shorter than 255 characters.
+ // After 255 characters, Windows will truncate the value.
+ // As for the username, the spec does not mention a limit in length
+ if second_part.len() > 255 {
+ return Err("Password length cannot exceed 255 characters".to_owned());
+ }
+
+ auth::RequiredAuthPassword::Plain(second_part.to_owned())
};
Ok(auth::RequiredAuth {