()
| 10 | use rustls::Session; |
| 11 | |
| 12 | fn main() { |
| 13 | let hostname = "michael.kefeder.at"; |
| 14 | let host = "127.0.0.1:12321"; |
| 15 | let mut config = rustls::ClientConfig::new(); |
| 16 | config |
| 17 | .root_store |
| 18 | .add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); |
| 19 | |
| 20 | let dns_name = webpki::DNSNameRef::try_from_ascii_str(hostname).unwrap(); |
| 21 | let mut sess = rustls::ClientSession::new(&Arc::new(config), dns_name); |
| 22 | let mut sock = TcpStream::connect(host).unwrap(); |
| 23 | let mut tls = rustls::Stream::new(&mut sess, &mut sock); |
| 24 | tls.write_all(b"Hello bob\n").unwrap(); |
| 25 | let ciphersuite = tls.sess.get_negotiated_ciphersuite().unwrap(); |
| 26 | writeln!( |
| 27 | &mut std::io::stderr(), |
| 28 | "Current ciphersuite: {:?}", |
| 29 | ciphersuite.suite |
| 30 | ) |
| 31 | .unwrap(); |
| 32 | let mut plaintext = [0u8; 1024]; |
| 33 | let num_bytes = tls.read(&mut plaintext).unwrap(); |
| 34 | if num_bytes > 0 { |
| 35 | stdout().write_all(&plaintext).unwrap(); |
| 36 | } |
| 37 | println!("{:?}", num_bytes); |
| 38 | } |
nothing calls this directly
no outgoing calls
no test coverage detected