libtls 0.0.1

Basic Rust bindings to OpenBSD's libtls
Documentation
// This file is released under the same terms as Rust itself.
use super::*;
use std::path::Path;
use std::io::prelude::*;

#[test]
pub fn connect_google() {
    let session = b"GET / HTTP/1.1\r\nUser-Agent: rust-libtls test suite (https://github.com/notriddle/rust-libtls)\r\nAccept: text/html\r\n\r\n";
    let mut config = Config::default();
    let file = {
        let mut file = "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem";
        for f in &["/etc/ssl/certs/ca-bundle.trust.crt", "/etc/ssl/certs/ca-certificates.crt", "/etc/ssl/certs/ca-bundle.crt"] {
            if Path::new(f).is_file() {
                file = f;
            }
        }
        file
    };
    config.set_ca_file(file).expect("Failed to set CA cert");
    let mut stream = config.connect(("google.com", 443)).expect("Failed to connect");
    stream.write(session).expect("Failed to write");
    let mut buf = vec![0; 1024];
    stream.read(&mut buf).expect("Failed to read");
    for b in &buf {
    	if *b == b'<' {
    		return;
    	}
    }
    panic!("{:?}", buf);
}