diff options
author | boastful-squirrel <boastful.squirrel@gmail.com> | 2019-04-26 17:05:59 +0000 |
---|---|---|
committer | boastful-squirrel <boastful.squirrel@gmail.com> | 2019-04-26 17:05:59 +0000 |
commit | 8440d59dd69594d8f09e640a02f0494544385d61 (patch) | |
tree | ee549f132ffd3fa44469d1e80813c1ac3c4b4dcd /src/args.rs | |
parent | Merge pull request #76 from KSXGitHub/pullrequest.hashed-password (diff) | |
download | miniserve-8440d59dd69594d8f09e640a02f0494544385d61.tar.gz miniserve-8440d59dd69594d8f09e640a02f0494544385d61.zip |
Cargo fmt
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/args.rs b/src/args.rs index 4077f35..b769a9b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -80,9 +80,7 @@ fn parse_interface(src: &str) -> Result<IpAddr, std::net::AddrParseError> { /// Checks wether the auth string is valid, i.e. it follows the syntax username:password fn parse_auth(src: &str) -> Result<auth::RequiredAuth, ContextualError> { let mut split = src.splitn(3, ':'); - let invalid_auth_format = Err( - ContextualError::new(ContextualErrorKind::InvalidAuthFormat) - ); + let invalid_auth_format = Err(ContextualError::new(ContextualErrorKind::InvalidAuthFormat)); let username = match split.next() { Some(username) => username, @@ -100,7 +98,9 @@ fn parse_auth(src: &str) -> Result<auth::RequiredAuth, ContextualError> { let hash_bin = if let Ok(hash_bin) = hex::decode(hash_hex) { hash_bin } else { - return Err(ContextualError::new(ContextualErrorKind::InvalidPasswordHash)) + return Err(ContextualError::new( + ContextualErrorKind::InvalidPasswordHash, + )); }; match second_part { @@ -108,16 +108,18 @@ fn parse_auth(src: &str) -> Result<auth::RequiredAuth, ContextualError> { "sha512" => auth::RequiredAuthPassword::Sha512(hash_bin.to_owned()), _ => { return Err(ContextualError::new( - ContextualErrorKind::InvalidHashMethod(second_part.to_owned()) + ContextualErrorKind::InvalidHashMethod(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(ContextualError::new(ContextualErrorKind::PasswordTooLongError)); + return Err(ContextualError::new( + ContextualErrorKind::PasswordTooLongError, + )); } auth::RequiredAuthPassword::Plain(second_part.to_owned()) @@ -189,7 +191,10 @@ mod tests { } #[rstest_parametrize( - auth_string, username, password, encrypt, + auth_string, + username, + password, + encrypt, case("username:password", "username", "password", "plain"), case("username:sha256:abcd", "username", "abcd", "sha256"), case("username:sha512:abcd", "username", "abcd", "sha512") |