#postgresql #tokio #hash #generic #tls #aws-lc-rs

tokio-postgres-generic-rustls

rustls-backed TLS for tokio-postgres without a required crypto backend

1 unstable release

0.1.0 May 4, 2024

#10 in #aws-lc-rs

Download history 20/week @ 2025-08-26 29/week @ 2025-09-02 63/week @ 2025-09-09 189/week @ 2025-09-16 259/week @ 2025-09-23 281/week @ 2025-09-30 324/week @ 2025-10-07 317/week @ 2025-10-14 344/week @ 2025-10-21 308/week @ 2025-10-28 460/week @ 2025-11-04 319/week @ 2025-11-11 297/week @ 2025-11-18 339/week @ 2025-11-25 366/week @ 2025-12-02 356/week @ 2025-12-09

1,419 downloads per month
Used in pict-rs

MIT/Apache

22KB
271 lines

tokio-postgres-generic-rustls

An impelementation of TLS based on rustls for tokio-postgres

This crate allows users to select a crypto backend, or bring their own, rather than relying on primitives provided by ring directly. This is done through the use of x509-cert for certificate parsing rather than X509-certificate, while also adding an abstraction for computing digests.

By default, tokio-postgres-generic-rustls does not provide a digest implementation, but one or more are provided behind crate features.

Feature Impelementation
aws-lc-rs AwsLcRsDigest
ring RingDigest
rustcrypto RustcryptoDigest

Usage

Using this crate is fairly straightforward. First, select your digest impelementation via crate features (or provide your own), then construct rustls connector for tokio-postgres with your rustls client configuration.

The following example demonstrates providing a custom digest backend.

use tokio_postgres_generic_rustls::{DigestImplementation, DigestAlgorithm, MakeRustlsConnect};

#[derive(Clone)]
struct DemoDigest;

impl DigestImplementation for DemoDigest {
    fn digest(&self, algorithm: DigestAlgorithm, bytes: &[u8]) -> Vec<u8> {
        todo!("digest it")
    }
}

fn main() {
    let cert_store = rustls::RootCertStore::empty();

    let config = rustls::ClientConfig::builder()
        .with_root_certificates(cert_store)
        .with_no_client_auth();

    let tls = MakeRustlsConnect::new(config, DemoDigest);

    let connect_future = tokio_postgres::connect("postgres://username:password@localhost:5432/db", tls);

    // connect_future.await;
}

License

This project is licensed under either of

at your option.

Dependencies

~15–38MB
~743K SLoC