| Crates.io | tls-helpers |
| lib.rs | tls-helpers |
| version | 0.2.0 |
| created_at | 2024-07-29 00:05:37.021491+00 |
| updated_at | 2026-01-04 17:03:17.900581+00 |
| description | helpers for creating tls tcp connections |
| homepage | |
| repository | https://github.com/wavey-ai/tls-helpers |
| max_upload_size | |
| id | 1318331 |
| size | 21,720 |
A Rust library that simplifies working with TLS certificates and keys in base64 format. This library provides convenient utilities for creating TLS acceptors and connectors from base64-encoded certificates and private keys.
rustls for robust TLS implementationuse tls_helpers::{certs_from_base64, privkey_from_base64};
// Load certificates from base64
let certs = certs_from_base64(&cert_base64_string)?;
// Load private key from base64
let private_key = privkey_from_base64(&key_base64_string)?;
use tls_helpers::tls_connector_from_base64;
// Create a TLS connector with custom CA certificate
let connector = tls_connector_from_base64(&ca_cert_base64)?;
// Use the connector with a TLS connection
let stream = connector.connect("example.com", tcp_stream).await?;
use tls_helpers::tls_acceptor_from_base64;
// Create a TLS acceptor with HTTP/1.1 and HTTP/2 support
let acceptor = tls_acceptor_from_base64(
&cert_base64,
&key_base64,
true, // Enable HTTP/1.x
true // Enable HTTP/2
)?;
// Use the acceptor with incoming connections
let tls_stream = acceptor.accept(tcp_stream).await?;
use tls_helpers::from_base64_raw;
// Decode raw base64 data
let raw_bytes = from_base64_raw(&base64_string)?;
The library uses standard Rust error handling patterns:
io::Result<T> for basic operationsResult<T, Box<dyn std::error::Error>> or Result<T, Box<dyn std::error::Error + Send + Sync>>rustls instead of OpenSSL for improved memory safetyrustlsbase64 crateArc for multiple connectionsuse tls_helpers::tls_acceptor_from_base64;
use tokio::net::TcpListener;
async fn run_server(cert_base64: &str, key_base64: &str) -> Result<(), Box<dyn std::error::Error>> {
let acceptor = tls_acceptor_from_base64(cert_base64, key_base64, true, true)?;
let listener = TcpListener::bind("0.0.0.0:443").await?;
while let Ok((stream, _)) = listener.accept().await {
let tls_stream = acceptor.accept(stream).await?;
// Handle the TLS stream...
}
Ok(())
}
use tls_helpers::tls_connector_from_base64;
use tokio::net::TcpStream;
async fn connect_client(ca_cert_base64: &str) -> Result<(), Box<dyn std::error::Error>> {
let connector = tls_connector_from_base64(ca_cert_base64)?;
let tcp_stream = TcpStream::connect("example.com:443").await?;
let tls_stream = connector.connect("example.com", tcp_stream).await?;
// Use the TLS stream...
Ok(())
}
MIT