diff options
Diffstat (limited to '')
-rw-r--r-- | src/args.rs | 21 | ||||
-rw-r--r-- | src/auth.rs | 9 | ||||
-rw-r--r-- | src/errors.rs | 5 |
3 files changed, 24 insertions, 11 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") diff --git a/src/auth.rs b/src/auth.rs index e75f498..d8de30e 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -165,13 +165,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, diff --git a/src/errors.rs b/src/errors.rs index 833e9c4..9f0a418 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -33,7 +33,10 @@ pub enum ContextualErrorKind { InvalidAuthFormat, /// This error might occure if the hash method is neither sha256 nor sha512 - #[fail(display = "{} is not a valid hashing method. Expected sha256 or sha512", _0)] + #[fail( + display = "{} is not a valid hashing method. Expected sha256 or sha512", + _0 + )] InvalidHashMethod(String), /// This error might occur if the HTTP auth hash password is not a valid hex code |