pub struct TlsAcceptor(_);
A builder for server-side TLS connections.
use native_tls::{Pkcs12, TlsAcceptor, TlsStream};
use std::fs::File;
use std::io::{Read};
use std::net::{TcpListener, TcpStream};
use std::sync::Arc;
use std::thread;
let mut file = File::open("identity.pfx").unwrap();
let mut pkcs12 = vec![];
file.read_to_end(&mut pkcs12).unwrap();
let pkcs12 = Pkcs12::from_der(&pkcs12, "hunter2").unwrap();
let listener = TcpListener::bind("0.0.0.0:8443").unwrap();
let acceptor = TlsAcceptor::builder(pkcs12).unwrap().build().unwrap();
let acceptor = Arc::new(acceptor);
fn handle_client(stream: TlsStream<TcpStream>) {
}
for stream in listener.incoming() {
match stream {
Ok(stream) => {
let acceptor = acceptor.clone();
thread::spawn(move || {
let stream = acceptor.accept(stream).unwrap();
handle_client(stream);
});
}
Err(e) => { }
}
}
Returns a new builder for a TlsAcceptor
.
This builder is created with a key/certificate pair in the pkcs12
archived passed in. The returned builder will use that key/certificate
to send to clients which it connects to.
Initiates a TLS handshake.
If the socket is nonblocking and a WouldBlock
error is returned during
the handshake, a HandshakeError::Interrupted
error will be returned
which can be used to restart the handshake when the socket is ready
again.
Performs copy-assignment from source
. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
[+]
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
[−]
🔬 This is a nightly-only experimental API. (try_from
)
[+]
[+]
[−]
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static