"ssl::SslStream::connect" -- "no associated item named `connect` "

I'm using the latest version of OpenSSL in my Rust application:

let mut abc = ssl::SslStream::connect(&sctx, tcp_conn).unwrap();

throws an exception:

error: no associated item named `connect` found for type `openssl::ssl::SslStream<_>` in the current scope
 --> src/main.rs:7:19
  |
7 |     let mut abc = ssl::SslStream::connect(&sctx, tcp_conn).unwrap();
  |                   ^^^^^^^^^^^^^^^^^^^^^^^

I have imported everything:

extern crate openssl;

use std::net::TcpStream;
use openssl::ssl;

This previously worked, around a few months ago and the function connect existed.

openssl version 0.9.8

That API has been adjusted: openssl::ssl::Ssl - Rust

You should be using openssl::ssl::SslConnector - Rust instead of Ssl directly, though.

1 Like

Now it has 3 parameters, how should I use it?

What 3 parameters?

let mut abc = ssl::SslStream::connect(&sctx, tcp_conn).unwrap();

is now

let ssl = ssl::Ssl::new(&sctx).unwrap();
let mut abc = ssl.connect(tcp_conn).unwrap();

But again, you should use SslConnector:

let connector = SslConnectorBuilder::new(SslMethod::tls()).unwrap().build().unwrap();
let mut abc = connector.connect("google.com", tcp_conn).unwrap();
1 Like

error: no method named unwrap found for type openssl::ssl::SslConnector in the current scope

Oh right, remove the last unwrap.