diff options
author | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-04-13 19:44:17 +0000 |
---|---|---|
committer | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-04-13 19:44:17 +0000 |
commit | d94f67e0c87b07bd747f357983253eee5c4a81b5 (patch) | |
tree | 7abd7ffccb5e7239f0f943465a07d11e75269eb5 /src/args.rs | |
parent | Made code more idiomatic (diff) | |
download | miniserve-d94f67e0c87b07bd747f357983253eee5c4a81b5.tar.gz miniserve-d94f67e0c87b07bd747f357983253eee5c4a81b5.zip |
Fixed auth check
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/args.rs b/src/args.rs index 516e0b6..d1250c0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -77,13 +77,24 @@ 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<(String, String), String> { - match src.find(':') { - Some(_) => { - let split = src.split(':').collect::<Vec<_>>(); - Ok((split[0].to_owned(), split[1].to_owned())) - } - None => Err("Correct format is username:password".to_owned()), + let mut split = src.splitn(2, ':'); + + let username = match split.next() { + Some(username) => username, + None => return Err("Invalid credentials string, expected format is username:password".to_owned()) + }; + + let password = match split.next() { + Some(password) => password, + None => return Err("Invalid credentials string, expected format is username:password".to_owned()) + }; + // Should we allow empty passwords ? + + if username.len() > 255 { + return Err("Username length cannot exceed 255 characters".to_owned()); } + + Ok((username.to_owned(), password.to_owned())) } /// Parses the command line arguments |