aboutsummaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorkhai96_ <hvksmr1996@gmail.com>2019-05-16 09:53:27 +0000
committerkhai96_ <hvksmr1996@gmail.com>2019-05-16 09:53:27 +0000
commit784b5fd79b071937ca1ade12caf9be291b53dff6 (patch)
tree08171389b4e97e03a4d652f255c23c11a5958fe4 /src/args.rs
parentRefactoring: Use immutable HashMap (diff)
downloadminiserve-784b5fd79b071937ca1ade12caf9be291b53dff6.tar.gz
miniserve-784b5fd79b071937ca1ade12caf9be291b53dff6.zip
Make some changes
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/args.rs b/src/args.rs
index 4851b41..0ec8a22 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -41,7 +41,7 @@ struct CLIArgs {
/// Set authentication. Currently supported formats:
/// username:password, username:sha256:hash, username:sha512:hash
#[structopt(short = "a", long = "auth", parse(try_from_str = "parse_auth"))]
- auth: Option<auth::RequiredAuth>,
+ auth: Vec<auth::RequiredAuth>,
/// Generate a random 6-hexdigit route
#[structopt(long = "random-route")]
@@ -77,21 +77,8 @@ fn parse_interface(src: &str) -> Result<IpAddr, std::net::AddrParseError> {
src.parse::<IpAddr>()
}
-/// Parse a string of multiple authentication requirements
+/// Parse authentication requirement
fn parse_auth(src: &str) -> Result<auth::RequiredAuth, ContextualError> {
- let required_auth = src
- .split_whitespace()
- .map(parse_single_auth)
- .collect::<Result<Vec<_>, ContextualError>>()?
- .iter()
- .cloned()
- .collect::<auth::RequiredAuth>();
-
- Ok(required_auth)
-}
-
-/// Parse a single authentication requirement
-fn parse_single_auth(src: &str) -> Result<(String, auth::RequiredAuthPassword), ContextualError> {
let mut split = src.splitn(3, ':');
let invalid_auth_format = Err(ContextualError::InvalidAuthFormat);
@@ -132,7 +119,10 @@ fn parse_single_auth(src: &str) -> Result<(String, auth::RequiredAuthPassword),
auth::RequiredAuthPassword::Plain(second_part.to_owned())
};
- Ok((username.to_owned(), password))
+ Ok(auth::RequiredAuth {
+ username: username.to_owned(),
+ password,
+ })
}
/// Parses the command line arguments