Crate tcp_stream
source · [−]Expand description
std::net::TCP stream on steroids
tcp-stream is a library aiming at providing TLS support to std::net::TcpStream
Examples
To connect to a remote server:
use tcp_stream::{HandshakeError, TcpStream, TLSConfig};
use std::io::{self, Read, Write};
fn main() {
    let mut stream = TcpStream::connect("google.com:443").unwrap();
    stream.set_nonblocking(true).unwrap();
    while !stream.is_connected() {
        if stream.try_connect().unwrap() {
            break;
        }
    }
    let mut stream = stream.into_tls("google.com", TLSConfig::default());
    while let Err(HandshakeError::WouldBlock(mid_handshake)) = stream {
        stream = mid_handshake.handshake();
    }
    let mut stream = stream.unwrap();
    while let Err(err) = stream.write_all(b"GET / HTTP/1.0\r\n\r\n") {
        if err.kind() != io::ErrorKind::WouldBlock {
            panic!("error: {:?}", err);
        }
    }
    stream.flush().unwrap();
    let mut res = vec![];
    while let Err(err) = stream.read_to_end(&mut res) {
        if err.kind() != io::ErrorKind::WouldBlock {
            panic!("stream error: {:?}", err);
        }
    }
    println!("{}", String::from_utf8_lossy(&res));
}Structs
Holds PKCS#12 DER-encoded identity and decryption password
Reexport native-tls’s TlsConnector
A builder for client-side TLS connections.
Reexport openssl’s TlsConnector
A type which wraps client-side streams in a TLS session.
Reexport openssl’s TlsConnector
A type specifying the kind of protocol an SslContext will speak.
Holds PKCS#12 DER-encoded identity and decryption password
Holds extra TLS configuration
Reexport rustls-connector’s TlsConnector
The connector
Reexport rustls-connector’s TlsConnector
Configuration helper for RustlsConnector
Holds extra TLS configuration
Enums
An error returned while performing the handshake
A TLS stream which has been interrupted during the handshake
Wrapper around plain or TLS TCP streams
Type Definitions
Holds either the TLS TcpStream result or the current handshake state
A HandshakeError from native-tls
A MidHandshakeTlsStream from native-tls
A TcpStream wrapped by native-tls
An ErrorStack from openssl
A HandshakeError from openssl
A MidHandshakeTlsStream from openssl
A TcpStream wrapped by openssl
A HandshakeError from rustls-connector
A MidHandshakeTlsStream from rustls-connector
A TcpStream wrapped by rustls