Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Rust bindings for LibreSSL's libtls.
The LibreSSL project provides a free TLS and crypto stack that was forked from OpenSSL in 2014. The goals are to provide a modernized codebase, improved security, and to apply best practice development processes.
LibreSSL provides C APIs that are compatible to OpenSSL's libssl and libcrypto libraries. It also provides libtls, a new TLS library that is designed to make it easier to write foolproof applications.
This workspace of Rust crates provides language bindings for libtls only, as the other LibreSSL APIs can be used with the existing rust-openssl crate. LibreSSL versions 2.9.0 through 3.0.2 (or later) are supported.
The following crates are included:
- libtls-sys: FFI bindings.
- libtls: Rust bindings.
- tokio-libtls: Tokio bindings.
Minimum Rust version
Async I/O with tokio-libtls requires Rust 1.39 or later for
async-await. This crate does not provide any backwards
compatibility but you can use version 1.0.0
on older Rust versions.
Examples
use ;
The same configuration can be created using the TlsConfigBuilder
builder pattern:
A TLS connection:
use ;
use ;
A non-blocking and asynchronous TLS connection using Tokio and the tokio-libtls crate:
use io;
use ;
use *;
async
async
An asynchronous TLS server:
async fn echo_server(cert: &str, key: &str) -> io::Result<()> {
let config = TlsConfigBuilder::new()
.keypair_file(cert, key, None)
.build()?;
let addr: SocketAddr = "[::1]:7".parse().unwrap();
let mut listener = TcpListener::bind(&addr).await?;
loop {
let (tcp, _) = listener.accept().await?;
let mut tls = AsyncTls::accept_stream(tcp, &config, None).await?;
tokio::spawn(async move {
loop {
let mut buf = vec![0u8; 1024];
if !tls.read(&mut buf).await.is_ok() || !tls.write_all(&buf).await.is_ok() {
break;
}
}
});
}
}
Copyright and license
Licensed under an OpenBSD-ISC-style license, see LICENSE for details.