pub fn new(
        ctxs: &Vec<SniContext>,
        domain_index: DomainIndex,
    ) -> Result<ResolvesServerCertUsingSNI> {
        let mut sni_rustls_map = ResolvesServerCertUsingSNI {
            domain_index: std::sync::RwLock::new(Some(domain_index)),
            by_name: std::sync::RwLock::new(Some(HashMap::new())),
        };

        for ctx in ctxs.iter() {
            if ctx.ssl.is_none() {
                continue;
            }

            let ssl = ctx.ssl.as_ref().unwrap();

            let key = load_private_key(&ssl.key)
                .map_err(|e| anyhow::anyhow!("err:load key => key:{}, e{}", ssl.key, e))
                .and_then(|key| {
                    rustls::sign::any_supported_type(&key)
                        .map_err(|_| anyhow::anyhow!("err:load key => key:{}, e:{}", ssl.key, rustls::Error::General("invalid private key".into())))
                })?;

            let cert = load_certs(&ssl.cert)
                .map_err(|e| anyhow::anyhow!("err:load cert => cert:{}, e{}", ssl.cert, e))?;

            let certified_key = rustls::sign::CertifiedKey::new(cert, key);
            sni_rustls_map.add(ctx.index, certified_key)?;
        }

        Ok(sni_rustls_map)
    }
/// Create a new and empty (ie, knows no certificates) resolver.
Create a new and empty  resolver.
Create a new and empty resolver .
pub fn new(
        ctxs: &Vec<SniContext>,
        domain_index: DomainIndex,
    ) -> Result<ResolvesServerCertUsingSNI> {
        let mut sni_rustls_map = ResolvesServerCertUsingSNI {
            domain_index: std::sync::RwLock::new(Some(domain_index)),
            by_name: std::sync::RwLock::new(Some(HashMap::new())),
        };
        for ctx in ctxs.iter() {
            if ctx.ssl.is_none() {
                continue;
            }
            let ssl = ctx.ssl.as_ref().unwrap();
            let key = load_private_key(&ssl.key)
                .map_err(|e| anyhow::anyhow!("err:load key => key:{}, e{}", ssl.key, e))
                .and_then(|key| {
                    rustls::sign::any_supported_type(&key)
                        .map_err(|_| anyhow::anyhow!("err:load key => key:{}, e:{}", ssl.key, rustls::Error::General("invalid private key".into())))
                })?;
            let cert = load_certs(&ssl.cert)
                .map_err(|e| anyhow::anyhow!("err:load cert => cert:{}, e{}", ssl.cert, e))?;
            let certified_key = rustls::sign::CertifiedKey::new(cert, key);
            sni_rustls_map.add(ctx.index, certified_key)?;
        }
        Ok(sni_rustls_map)
    }
pub fn new ( ctxs : & Vec < SniContext > , domain_index : DomainIndex , ) -> Result < ResolvesServerCertUsingSNI > { let mut sni_rustls_map = ResolvesServerCertUsingSNI { domain_index : std :: sync :: RwLock :: new ( Some ( domain_index ) ) , by_name : std :: sync :: RwLock :: new ( Some ( HashMap :: new ( ) ) ) , } ; for ctx in ctxs . iter ( ) { if ctx . ssl . is_none ( ) { continue ; } let ssl = ctx . ssl . as_ref ( ) . unwrap ( ) ; let key = load_private_key ( & ssl . key ) . map_err ( | e | anyhow :: anyhow ! ( " " ssl key e ) ) . and_then ( | key | { rustls :: sign :: any_supported_type ( & key ) . map_err ( | _ | anyhow :: anyhow ! ( " " ssl key rustls Error General ( " " into ( ) ) ) ) } ) ? ; let cert = load_certs ( & ssl . cert ) . map_err ( | e | anyhow :: anyhow ! ( " " ssl cert e ) ) ? ; let certified_key = rustls :: sign :: CertifiedKey :: new ( cert , key ) ; sni_rustls_map . add ( ctx . index , certified_key ) ? ; } Ok ( sni_rustls_map ) }
Create a new and empty (ie, knows no certificates) resolver.
Create a new and empty ( ie knows no certificates ) resolver .
ctxs
&Vec<SniContext>
domain_index
DomainIndex