fix(auth): handle single + response (#145)

This commit is contained in:
Friedel Ziegelmayer 2019-10-21 16:49:15 +02:00 committed by Jon Gjengset
parent 0e5aa5c004
commit 465481de88

View file

@ -323,7 +323,11 @@ impl<T: Read + Write> Client<T> {
// early (see also comment on `login`) // early (see also comment on `login`)
ok_or_unauth_client_err!(self.readline(&mut line), self); ok_or_unauth_client_err!(self.readline(&mut line), self);
if line.starts_with(b"+ ") { // Some servers will only send `+\r\n`.
if line.starts_with(b"+ ") || &line == b"+\r\n" {
let challenge = if &line == b"+\r\n" {
Vec::new()
} else {
let line_str = ok_or_unauth_client_err!( let line_str = ok_or_unauth_client_err!(
match str::from_utf8(line.as_slice()) { match str::from_utf8(line.as_slice()) {
Ok(line_str) => Ok(line_str), Ok(line_str) => Ok(line_str),
@ -331,14 +335,17 @@ impl<T: Read + Write> Client<T> {
}, },
self self
); );
let data = ok_or_unauth_client_err!(parse_authenticate_response(line_str), self); let data =
let challenge = ok_or_unauth_client_err!( ok_or_unauth_client_err!(parse_authenticate_response(line_str), self);
ok_or_unauth_client_err!(
base64::decode(data).map_err(|e| Error::Parse(ParseError::Authentication( base64::decode(data).map_err(|e| Error::Parse(ParseError::Authentication(
data.to_string(), data.to_string(),
Some(e) Some(e)
))), ))),
self self
); )
};
let raw_response = &authenticator.process(&challenge); let raw_response = &authenticator.process(&challenge);
let auth_response = base64::encode(raw_response); let auth_response = base64::encode(raw_response);
ok_or_unauth_client_err!( ok_or_unauth_client_err!(