pub async fn authenticate(&mut self, mut handler: Ssh2AuthHandler<'_>) -> io::Result<()> {
        // If already authenticated, exit
        if self.authenticated {
            return Ok(());
        }

        // Perform the authentication by listening for events and continuing to handle them
        // until authenticated
        while let Ok(event) = self.events.recv().await {
            match event {
                WezSessionEvent::Banner(banner) => {
                    if let Some(banner) = banner {
                        (handler.on_banner)(banner.as_ref());
                    }
                }
                WezSessionEvent::HostVerify(verify) => {
                    let verified = (handler.on_host_verify)(verify.message.as_str())?;
                    verify
                        .answer(verified)
                        .compat()
                        .await
                        .map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;
                }
                WezSessionEvent::Authenticate(mut auth) => {
                    let ev = Ssh2AuthEvent {
                        username: auth.username.clone(),
                        instructions: auth.instructions.clone(),
                        prompts: auth
                            .prompts
                            .drain(..)
                            .map(|p| Ssh2AuthPrompt {
                                prompt: p.prompt,
                                echo: p.echo,
                            })
                            .collect(),
                    };

                    let answers = (handler.on_authenticate)(ev)?;
                    auth.answer(answers)
                        .compat()
                        .await
                        .map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;
                }
                WezSessionEvent::Error(err) => {
                    (handler.on_error)(&err);
                    return Err(io::Error::new(io::ErrorKind::PermissionDenied, err));
                }
                WezSessionEvent::Authenticated => break,
            }
        }

        // Mark as authenticated
        self.authenticated = true;

        Ok(())
    }
/// Authenticates the [`Ssh2Session`] if not already authenticated
Authenticates the [`Ssh2Session`] if not already authenticated
Authenticates the [ ` Ssh2Session ` ] if not already authenticated
pub async fn authenticate(&mut self, mut handler: Ssh2AuthHandler<'_>) -> io::Result<()> {
        // If already authenticated, exit
        if self.authenticated {
            return Ok(());
        }
        // Perform the authentication by listening for events and continuing to handle them
        // until authenticated
        while let Ok(event) = self.events.recv().await {
            match event {
                WezSessionEvent::Banner(banner) => {
                    if let Some(banner) = banner {
                        (handler.on_banner)(banner.as_ref());
                    }
                }
                WezSessionEvent::HostVerify(verify) => {
                    let verified = (handler.on_host_verify)(verify.message.as_str())?;
                    verify
                        .answer(verified)
                        .compat()
                        .await
                        .map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;
                }
                WezSessionEvent::Authenticate(mut auth) => {
                    let ev = Ssh2AuthEvent {
                        username: auth.username.clone(),
                        instructions: auth.instructions.clone(),
                        prompts: auth
                            .prompts
                            .drain(..)
                            .map(|p| Ssh2AuthPrompt {
                                prompt: p.prompt,
                                echo: p.echo,
                            })
                            .collect(),
                    };
                    let answers = (handler.on_authenticate)(ev)?;
                    auth.answer(answers)
                        .compat()
                        .await
                        .map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;
                }
                WezSessionEvent::Error(err) => {
                    (handler.on_error)(&err);
                    return Err(io::Error::new(io::ErrorKind::PermissionDenied, err));
                }
                WezSessionEvent::Authenticated => break,
            }
        }
        // Mark as authenticated
        self.authenticated = true;
        Ok(())
    }
pub async fn authenticate ( & mut self , mut handler : Ssh2AuthHandler < ' _ > ) -> io :: Result < ( ) > { // If already authenticated, exit if self . authenticated { return Ok ( ( ) ) ; } // Perform the authentication by listening for events and continuing to handle them // until authenticated while let Ok ( event ) = self . events . recv ( ) . await { match event { WezSessionEvent :: Banner ( banner ) => { if let Some ( banner ) = banner { ( handler . on_banner ) ( banner . as_ref ( ) ) ; } } WezSessionEvent :: HostVerify ( verify ) => { let verified = ( handler . on_host_verify ) ( verify . message . as_str ( ) ) ? ; verify . answer ( verified ) . compat ( ) . await . map_err ( | x | io :: Error :: new ( io :: ErrorKind :: Other , x ) ) ? ; } WezSessionEvent :: Authenticate ( mut auth ) => { let ev = Ssh2AuthEvent { username : auth . username . clone ( ) , instructions : auth . instructions . clone ( ) , prompts : auth . prompts . drain ( .. ) . map ( | p | Ssh2AuthPrompt { prompt : p . prompt , echo : p . echo , } ) . collect ( ) , } ; let answers = ( handler . on_authenticate ) ( ev ) ? ; auth . answer ( answers ) . compat ( ) . await . map_err ( | x | io :: Error :: new ( io :: ErrorKind :: Other , x ) ) ? ; } WezSessionEvent :: Error ( err ) => { ( handler . on_error ) ( & err ) ; return Err ( io :: Error :: new ( io :: ErrorKind :: PermissionDenied , err ) ) ; } WezSessionEvent :: Authenticated => break , } } // Mark as authenticated self . authenticated = true ; Ok ( ( ) ) }
Authenticates the [`Ssh2Session`] if not already authenticated
Authenticates the [ ` Ssh2Session ` ] if not already authenticated
&mut self
handler
Ssh2AuthHandler<'_>