diff options
author | khai96_ <hvksmr1996@gmail.com> | 2019-04-27 06:56:45 +0000 |
---|---|---|
committer | khai96_ <hvksmr1996@gmail.com> | 2019-04-27 06:56:45 +0000 |
commit | 58eee2f329859c33008a5b8b5af53189b2b4ab4a (patch) | |
tree | 2aa131c47eec383ca9dea843c735a05688fd7421 /src/args.rs | |
parent | Merge pull request #84 from KSXGitHub/patch-1 (diff) | |
download | miniserve-58eee2f329859c33008a5b8b5af53189b2b4ab4a.tar.gz miniserve-58eee2f329859c33008a5b8b5af53189b2b4ab4a.zip |
Combine ContextualError and ContextualErrorKind into one
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/args.rs b/src/args.rs index 4077f35..63799a0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use structopt::StructOpt; use crate::auth; -use crate::errors::{ContextualError, ContextualErrorKind}; +use crate::errors::{ContextualError}; use crate::themes; /// Possible characters for random routes @@ -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::InvalidAuthFormat); let username = match split.next() { Some(username) => username, @@ -100,16 +98,14 @@ 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::InvalidPasswordHash) }; match second_part { "sha256" => auth::RequiredAuthPassword::Sha256(hash_bin.to_owned()), "sha512" => auth::RequiredAuthPassword::Sha512(hash_bin.to_owned()), _ => { - return Err(ContextualError::new( - ContextualErrorKind::InvalidHashMethod(second_part.to_owned()) - )) + return Err(ContextualError::InvalidHashMethod(second_part.to_owned())) }, } } else { @@ -117,7 +113,7 @@ fn parse_auth(src: &str) -> Result<auth::RequiredAuth, ContextualError> { // 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::PasswordTooLongError); } auth::RequiredAuthPassword::Plain(second_part.to_owned()) |