pub fn new_from_response(mechanism: Mechanism,
                             credentials: Credentials,
                             response: &Response)
                             -> Result<AuthCommand, Error> {
        if !response.has_code(334) {
            return Err(Error::ResponseParsing("Expecting a challenge"));
        }

        let encoded_challenge = match response.first_word() {
            Some(challenge) => challenge.to_string(),
            None => return Err(Error::ResponseParsing("Could not read auth challenge")),
        };

        debug!("auth encoded challenge: {}", encoded_challenge);

        let decoded_challenge = match base64::decode(&encoded_challenge) {
            Ok(challenge) => {
                match String::from_utf8(challenge) {
                    Ok(value) => value,
                    Err(error) => return Err(Error::Utf8Parsing(error)),
                }
            }
            Err(error) => return Err(Error::ChallengeParsing(error)),
        };

        debug!("auth decoded challenge: {}", decoded_challenge);

        let response = Some(mechanism.response(&credentials, Some(decoded_challenge.as_ref()))?);

        Ok(AuthCommand { mechanism:   mechanism,
               credentials: credentials,
               challenge:   Some(decoded_challenge),
               response:    response, })
    }
/// Creates an AUTH command from a response that needs to be a
/// valid challenge (with 334 response code)
Creates an AUTH command from a response that needs to be a
valid challenge (with 334 response code)
Creates an AUTH command from a response that needs to be a valid challenge ( with 334 response code )
pub fn new_from_response(mechanism: Mechanism,
                             credentials: Credentials,
                             response: &Response)
                             -> Result<AuthCommand, Error> {
        if !response.has_code(334) {
            return Err(Error::ResponseParsing("Expecting a challenge"));
        }
        let encoded_challenge = match response.first_word() {
            Some(challenge) => challenge.to_string(),
            None => return Err(Error::ResponseParsing("Could not read auth challenge")),
        };
        debug!("auth encoded challenge: {}", encoded_challenge);
        let decoded_challenge = match base64::decode(&encoded_challenge) {
            Ok(challenge) => {
                match String::from_utf8(challenge) {
                    Ok(value) => value,
                    Err(error) => return Err(Error::Utf8Parsing(error)),
                }
            }
            Err(error) => return Err(Error::ChallengeParsing(error)),
        };
        debug!("auth decoded challenge: {}", decoded_challenge);
        let response = Some(mechanism.response(&credentials, Some(decoded_challenge.as_ref()))?);
        Ok(AuthCommand { mechanism:   mechanism,
               credentials: credentials,
               challenge:   Some(decoded_challenge),
               response:    response, })
    }
pub fn new_from_response ( mechanism : Mechanism , credentials : Credentials , response : & Response ) -> Result < AuthCommand , Error > { if ! response . has_code ( 334 ) { return Err ( Error :: ResponseParsing ( " " ) ) ; } let encoded_challenge = match response . first_word ( ) { Some ( challenge ) => challenge . to_string ( ) , None => return Err ( Error :: ResponseParsing ( " " ) ) , } ; debug ! ( " " encoded_challenge ) ; let decoded_challenge = match base64 :: decode ( & encoded_challenge ) { Ok ( challenge ) => { match String :: from_utf8 ( challenge ) { Ok ( value ) => value , Err ( error ) => return Err ( Error :: Utf8Parsing ( error ) ) , } } Err ( error ) => return Err ( Error :: ChallengeParsing ( error ) ) , } ; debug ! ( " " decoded_challenge ) ; let response = Some ( mechanism . response ( & credentials , Some ( decoded_challenge . as_ref ( ) ) ) ? ) ; Ok ( AuthCommand { mechanism : mechanism , credentials : credentials , challenge : Some ( decoded_challenge ) , response : response , } ) }
Creates an AUTH command from a response that needs to be a
valid challenge (with 334 response code)
Creates an AUTH command from a response that needs to be a valid challenge ( with 334 response code )
mechanism
Mechanism
credentials
Credentials
response
&Response
mechanism
Mechanism
credentials
Credentials
response
&Response