pub trait Auth {
type Output;
// Required methods
fn as_handshake_method(&self) -> Method;
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
stream: &'life1 mut TcpStream,
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
This trait is for defining the customized process of SOCKS5 authentication.
You can create your own authentication method by implementing this trait. Associate type Output indicates the result of authenticating. Note that this library will not implicitly close any connection even if the authentication failed.
§Example
use async_trait::async_trait;
use std::io::Result;
use socks5_proto::handshake::Method;
use socks5_server::Auth;
use tokio::net::TcpStream;
pub struct MyAuth;
#[async_trait]
impl Auth for MyAuth {
type Output = Result<usize>;
fn as_handshake_method(&self) -> Method {
Method(0xfe)
}
async fn execute(&self, stream: &mut TcpStream) -> Self::Output {
// do something on stream
Ok(1145141919810)
}
}