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


#1

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


#2

That API has been adjusted: https://docs.rs/openssl/0.9.6/openssl/ssl/struct.Ssl.html#method.new

You should be using https://docs.rs/openssl/0.9.6/openssl/ssl/struct.SslConnector.html instead of Ssl directly, though.


#3

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


#4

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();

#5

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


#6

Oh right, remove the last unwrap.