From 58eee2f329859c33008a5b8b5af53189b2b4ab4a Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sat, 27 Apr 2019 13:56:45 +0700 Subject: Combine ContextualError and ContextualErrorKind into one --- src/args.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/args.rs') 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 { /// Checks wether the auth string is valid, i.e. it follows the syntax username:password fn parse_auth(src: &str) -> Result { 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 { 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 { // 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()) -- cgit v1.2.3