spiral-auth 0.1.12

Spiral credentials: bearer tokens and the providers that obtain them
Documentation
//! The rustls crypto provider for credential requests and private-key signing.
//!
//! An application that installs a process-default provider chooses the crypto. Otherwise this
//! crate installs the one its `aws-lc` or `ring` feature selects. Without either, building an
//! HTTP client panics until the application installs a provider.

#[cfg(any(feature = "private-key-auth", feature = "browser-auth"))]
use std::sync::Arc;

#[cfg(any(
    feature = "private-key-auth",
    feature = "browser-auth",
    feature = "aws-lc",
    feature = "ring"
))]
use rustls::crypto::CryptoProvider;
#[cfg(feature = "aws-lc")]
use rustls::crypto::aws_lc_rs;
#[cfg(all(feature = "ring", not(feature = "aws-lc")))]
use rustls::crypto::ring;
/// Install the selected TLS crypto provider unless the application installed one first.
pub fn install_default_crypto_provider() {
    #[cfg(any(feature = "aws-lc", feature = "ring"))]
    if CryptoProvider::get_default().is_none() {
        #[cfg(feature = "aws-lc")]
        drop(aws_lc_rs::default_provider().install_default());
        #[cfg(all(feature = "ring", not(feature = "aws-lc")))]
        drop(ring::default_provider().install_default());
    }
}

#[cfg(any(feature = "private-key-auth", feature = "browser-auth"))]
use crate::{CredentialError, CredentialResult};

/// The process's rustls crypto provider, installing this crate's when the application chose none.
#[cfg(any(feature = "private-key-auth", feature = "browser-auth"))]
pub(crate) fn crypto_provider() -> CredentialResult<Arc<CryptoProvider>> {
    install_default_crypto_provider();
    CryptoProvider::get_default().cloned().ok_or_else(|| {
        CredentialError::invalid(
            "no rustls crypto provider: enable the `aws-lc` or `ring` feature, or install a \
             process-default provider first",
        )
    })
}