async fn authenticate(&mut self) -> Result<(String, String)> {
        trace!("Socks5Socket: authenticate()");
        let [version, user_len] =
            read_exact!(self.inner, [0u8; 2]).context("Can't read user len")?;
        debug!(
            "Auth: [version: {version}, user len: {len}]",
            version = version,
            len = user_len,
        );

        if user_len < 1 {
            return Err(SocksError::AuthenticationFailed(format!(
                "Username malformed ({} chars)",
                user_len
            )));
        }

        let username =
            read_exact!(self.inner, vec![0u8; user_len as usize]).context("Can't get username.")?;
        debug!("username bytes: {:?}", &username);

        let [pass_len] = read_exact!(self.inner, [0u8; 1]).context("Can't read pass len")?;
        debug!("Auth: [pass len: {len}]", len = pass_len,);

        if pass_len < 1 {
            return Err(SocksError::AuthenticationFailed(format!(
                "Password malformed ({} chars)",
                pass_len
            )));
        }

        let password =
            read_exact!(self.inner, vec![0u8; pass_len as usize]).context("Can't get password.")?;
        debug!("password bytes: {:?}", &password);

        let username = String::from_utf8(username).context("Failed to convert username")?;
        let password = String::from_utf8(password).context("Failed to convert password")?;
        let auth = self.config.auth.as_ref().context("No auth module")?;

        if auth.authenticate(&username, &password) {
            self.inner
                .write(&[1, consts::SOCKS5_REPLY_SUCCEEDED])
                .await
                .context("Can't reply auth success")?;
        } else {
            self.inner
                .write(&[1, consts::SOCKS5_AUTH_METHOD_NOT_ACCEPTABLE])
                .await
                .context("Can't reply with auth method not acceptable.")?;

            return Err(SocksError::AuthenticationRejected(format!(
                "Authentication with username `{}`, rejected.",
                username
            )));
        }

        info!("User `{}` logged successfully.", username);

        Ok((username, password))
    }
/// Only called if
///  - the client supports authentication via username/password
///  - this server has `Authentication` trait implemented.
Only called if
the client supports authentication via username/password
this server has `Authentication` trait implemented.
Only called if the client supports authentication via username / password this server has ` Authentication ` trait implemented .
async fn authenticate(&mut self) -> Result<(String, String)> {
        trace!("Socks5Socket: authenticate()");
        let [version, user_len] =
            read_exact!(self.inner, [0u8; 2]).context("Can't read user len")?;
        debug!(
            "Auth: [version: {version}, user len: {len}]",
            version = version,
            len = user_len,
        );
        if user_len < 1 {
            return Err(SocksError::AuthenticationFailed(format!(
                "Username malformed ({} chars)",
                user_len
            )));
        }
        let username =
            read_exact!(self.inner, vec![0u8; user_len as usize]).context("Can't get username.")?;
        debug!("username bytes: {:?}", &username);
        let [pass_len] = read_exact!(self.inner, [0u8; 1]).context("Can't read pass len")?;
        debug!("Auth: [pass len: {len}]", len = pass_len,);
        if pass_len < 1 {
            return Err(SocksError::AuthenticationFailed(format!(
                "Password malformed ({} chars)",
                pass_len
            )));
        }
        let password =
            read_exact!(self.inner, vec![0u8; pass_len as usize]).context("Can't get password.")?;
        debug!("password bytes: {:?}", &password);
        let username = String::from_utf8(username).context("Failed to convert username")?;
        let password = String::from_utf8(password).context("Failed to convert password")?;
        let auth = self.config.auth.as_ref().context("No auth module")?;
        if auth.authenticate(&username, &password) {
            self.inner
                .write(&[1, consts::SOCKS5_REPLY_SUCCEEDED])
                .await
                .context("Can't reply auth success")?;
        } else {
            self.inner
                .write(&[1, consts::SOCKS5_AUTH_METHOD_NOT_ACCEPTABLE])
                .await
                .context("Can't reply with auth method not acceptable.")?;
            return Err(SocksError::AuthenticationRejected(format!(
                "Authentication with username `{}`, rejected.",
                username
            )));
        }
        info!("User `{}` logged successfully.", username);
        Ok((username, password))
    }
async fn authenticate ( & mut self ) -> Result < ( String , String ) > { trace ! ( " " ) ; let [ version , user_len ] = read_exact ! ( self inner [ 0u8 2 ] ) . context ( " " ) ? ; debug ! ( " " version version len user_len ) ; if user_len < 1 { return Err ( SocksError :: AuthenticationFailed ( format ! ( " " user_len ) ) ) ; } let username = read_exact ! ( self inner vec [ 0u8 user_len as usize ] ) . context ( " " ) ? ; debug ! ( " " username ) ; let [ pass_len ] = read_exact ! ( self inner [ 0u8 1 ] ) . context ( " " ) ? ; debug ! ( " " len pass_len ) ; if pass_len < 1 { return Err ( SocksError :: AuthenticationFailed ( format ! ( " " pass_len ) ) ) ; } let password = read_exact ! ( self inner vec [ 0u8 pass_len as usize ] ) . context ( " " ) ? ; debug ! ( " " password ) ; let username = String :: from_utf8 ( username ) . context ( " " ) ? ; let password = String :: from_utf8 ( password ) . context ( " " ) ? ; let auth = self . config . auth . as_ref ( ) . context ( " " ) ? ; if auth . authenticate ( & username , & password ) { self . inner . write ( & [ 1 , consts :: SOCKS5_REPLY_SUCCEEDED ] ) . await . context ( " " ) ? ; } else { self . inner . write ( & [ 1 , consts :: SOCKS5_AUTH_METHOD_NOT_ACCEPTABLE ] ) . await . context ( " " ) ? ; return Err ( SocksError :: AuthenticationRejected ( format ! ( " " username ) ) ) ; } info ! ( " " username ) ; Ok ( ( username , password ) ) }
Only called if
 the client supports authentication via username/password
 this server has `Authentication` trait implemented.
Only called if the client supports authentication via username / password this server has ` Authentication ` trait implemented .
&mut self
&mut self