Rustls SNI Resolver
A minimal ResolvesServerCert implementation backed by
{ by_sni: HashMap<String, Arc<E>>, default: Option<Arc<E>> }, with
the whole struct designed to live behind an Arc<ArcSwap<_>> so a
config reload is one atomic pointer swap.
E is generic over the [EntryKey] trait, so callers can attach
their own per-cert state (expiry timestamps, OCSP staple handles,
ACME order IDs, …) without forking the resolver.
rustls's built-in ResolvesServerCertUsingSni returns None on
unmatched SNI with no built-in fallback hook — every operator-facing
TLS service ends up writing this small "with a default" variant by
hand.
Example
use Arc;
use ArcSwap;
use ;
#
Lookup semantics
CertStore::lookup(Option<&str>) returns:
- the entry under the matching SNI key, if one exists;
- otherwise the
defaultentry, if one is set; - otherwise
None.
Because rustls already ASCII-lowercases the server_name per RFC 6066
§ 3, populators should also store by_sni keys in lowercase. This
crate does not lowercase on insert — callers own that invariant
(typical populators read keys from configuration that has already been
normalized at parse time).
License
Released under the MIT License © 2026 Canmi