aboutsummaryrefslogtreecommitdiffstats
path: root/src/auth.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/auth.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/auth.rs')
-rw-r--r--src/auth.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/auth.rs b/src/auth.rs
index e75f498..8e6532b 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -3,7 +3,7 @@ use actix_web::middleware::{Middleware, Response};
use actix_web::{HttpRequest, HttpResponse, Result};
use sha2::{Digest, Sha256, Sha512};
-use crate::errors::{ContextualError, ContextualErrorKind};
+use crate::errors::{ContextualError};
pub struct Auth;
@@ -36,13 +36,13 @@ pub fn parse_basic_auth(
let basic_removed = authorization_header
.to_str()
.map_err(|e| {
- ContextualError::new(ContextualErrorKind::ParseError(
+ ContextualError::ParseError(
"HTTP authentication header".to_string(),
e.to_string(),
- ))
+ )
})?
.replace("Basic ", "");
- let decoded = base64::decode(&basic_removed).map_err(ContextualErrorKind::Base64DecodeError)?;
+ let decoded = base64::decode(&basic_removed).map_err(ContextualError::Base64DecodeError)?;
let decoded_str = String::from_utf8_lossy(&decoded);
let credentials: Vec<&str> = decoded_str.splitn(2, ':').collect();
@@ -97,9 +97,7 @@ impl Middleware<crate::MiniserveConfig> for Auth {
let auth_req = match parse_basic_auth(auth_headers) {
Ok(auth_req) => auth_req,
Err(err) => {
- let auth_err = ContextualError::new(
- ContextualErrorKind::HTTPAuthenticationError(Box::new(err)),
- );
+ let auth_err = ContextualError::HTTPAuthenticationError(Box::new(err));
return Ok(Response::Done(
HttpResponse::BadRequest().body(auth_err.to_string()),
));