aboutsummaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2019-04-27 19:31:07 +0000
committerGitHub <noreply@github.com>2019-04-27 19:31:07 +0000
commit18fcc8e699897ceca75920722531b79d909f28fc (patch)
tree9e855f3afbbe8237a09c9c364832f8c5aa4e57e8 /src/args.rs
parentDescribe hashed password feature in README (diff)
parentCombine ContextualError and ContextualErrorKind into one (diff)
downloadminiserve-18fcc8e699897ceca75920722531b79d909f28fc.tar.gz
miniserve-18fcc8e699897ceca75920722531b79d909f28fc.zip
Merge pull request #88 from KSXGitHub/combine-contextual-error
Combine ContextualError and ContextualErrorKind into one
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs14
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())