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
TlsConnectorA builder for client-side TLS connections. - Reexport openssl’s
TlsConnectorA type which wraps client-side streams in a TLS session. - Reexport openssl’s
TlsConnectorA type specifying the kind of protocol anSslContextwill speak. - Holds PKCS#12 DER-encoded identity and decryption password
- Holds extra TLS configuration
- Reexport rustls-connector’s
TlsConnectorThe connector - Reexport rustls-connector’s
TlsConnectorConfiguration helper forRustlsConnector - 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
TcpStreamresult or the current handshake state - A
HandshakeErrorfrom native-tls - A
MidHandshakeTlsStreamfrom native-tls - A
TcpStreamwrapped by native-tls - An
ErrorStackfrom openssl - A
HandshakeErrorfrom openssl - A
MidHandshakeTlsStreamfrom openssl - A
TcpStreamwrapped by openssl - A
HandshakeErrorfrom rustls-connector - A
MidHandshakeTlsStreamfrom rustls-connector - A
TcpStreamwrapped by rustls