reloading_resolver

Function reloading_resolver 

Source
pub async fn reloading_resolver(
    crypto_provider: &CryptoProvider,
    cert_path: PathBuf,
    key_path: PathBuf,
    interval: Duration,
) -> Result<Arc<dyn ResolvesServerCert>, AnyError>
Available on crate feature server only.
Expand description

Builds a [ResolvesServerCert] that reloads its certificate and key from disk on an interval.

Loads the PEM-encoded certificate chain from cert_path and the PEM-encoded private key from key_path using crypto_provider’s key provider, then spawns a background task that re-reads both files every interval. The returned resolver hands the most recently loaded CertifiedKey to rustls for each TLS handshake, so certificate rotation takes effect without restarting the server. See DEFAULT_CERT_RELOAD_INTERVAL for a sensible default.

The reload task is tied to the returned Arc and is aborted when the last reference is dropped. Reload failures on the interval are silently ignored; the previously loaded certificate remains in use.

§Errors

Returns an error if the initial certificate or key load fails (for example, the files do not exist, cannot be read, or cannot be parsed as PEM).