When trying to use tokio_native_tls' TlsConnector (tokio_native_tls::TlsConnector - Rust), I encountered an error stating that it requires 3 arguments but I only provided 2. Am I missing the "self" argument since the arguments required are self, domain and stream.
use futures::executor::block_on;
use tokio_native_tls::{ TlsConnector };
async fn async_main()
{
let tcp_stream = async_std::net::TcpStream::connect("127.0.0.1:4444").await;
match tcp_stream
{
Ok(working_stream) =>
{
let tokio_tls_connector = TlsConnector::connect("127.0.0.1:4444",working_stream);
//expected 3 arguments, supplied 2
}
Err(error) =>
{
panic!("cannot establish TCP stream {}",error);
}
}
}
fn main() {
async_std::task::block_on(async_main());
}
You need to first create a native_tls::TlsConnector then use tokio_tls_connector::TlsConnector::from(connector).connect("127.0.0.1:4444", working_stream).
I tried the following and encountered different errors.
let tcp_stream = tokio::net::TcpStream::connect("127.0.0.1:4444").await;
match tcp_stream
{
Ok(working_stream) =>
{
let mut native_tls_builder = native_tls::TlsConnector::builder();
native_tls_builder.danger_accept_invalid_certs(true);
native_tls_builder.danger_accept_invalid_hostnames(true);
native_tls_builder.use_sni(false);
let native_tls_connector = native_tls_builder.build().unwrap();
let tokio_tls_connector = tokio_native_tls::TlsConnector::from(native_tls_connector).connect("127.0.0.1:4444",working_stream);
//ERROR temporary value dropped while borrowed
//consider using a `let` binding to create a longer lived value
}
Err(error) =>
{
panic!("cannot establish TCP stream {}",error);
}
}
let tokio_tls_connector = tokio_native_tls::TlsConnector::from(native_tls_connector);
let tls_connector = tokio_tls_connector.connect("127.0.0.1:4444",working_stream);
//thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime'