From 8a548fd1eba41ecca91928b855eb4241352ba1d8 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Fri, 19 Apr 2019 22:44:31 +0700 Subject: Resolve https://github.com/svenstaro/miniserve/pull/76#discussion_r277011948 --- src/args.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src') 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 { 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 { -- cgit v1.2.3