pub fn new<P: AsRef<Path>>(cert_base_path: P, idle_timeout: Option<u64>) -> Result<Self> {
        let mut server_config = quinn::ServerConfig::default();
        if let Some(timeout) = idle_timeout {
            server_config.transport = Arc::new(utils::new_transport_cfg(timeout)?)
        };

        let mut server_config = quinn::ServerConfigBuilder::new(server_config);
        server_config.protocols(ALPN_QUIC_HTTP);

        let mut cert_path = PathBuf::new();
        cert_path.push(&cert_base_path);
        cert_path.push("cert.der");

        let mut key_path = PathBuf::new();
        key_path.push(&cert_base_path);
        key_path.push("key.der");

        let (cert, key) = match fs::read(&cert_path).and_then(|x| Ok((x, fs::read(&key_path)?))) {
            Ok(x) => x,
            Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
                info!("Generating self-signed certificate...");
                let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).map_err(
                    |err| {
                        Error::GeneralError(format!(
                            "Failed to generate self-signed certificate: {}",
                            err
                        ))
                    },
                )?;
                let key = cert.serialize_private_key_der();
                let cert = cert.serialize_der().map_err(|err| {
                    Error::GeneralError(format!("Failed to serialise certificate: {}", err))
                })?;
                fs::create_dir_all(cert_base_path).map_err(|err| {
                    Error::GeneralError(format!("Failed to create certificate directory: {}", err))
                })?;
                fs::write(&cert_path, &cert).map_err(|err| {
                    Error::GeneralError(format!("Failed to write certificate: {}", err))
                })?;
                fs::write(&key_path, &key).map_err(|err| {
                    Error::GeneralError(format!("Failed to write private key: {}", err))
                })?;
                (cert, key)
            }
            Err(e) => {
                return Err(Error::GeneralError(format!(
                    "Failed to read certificate: {}",
                    e
                )));
            }
        };
        let key = quinn::PrivateKey::from_der(&key).map_err(|err| {
            Error::GeneralError(format!("Failed parse private key from file: {}", err))
        })?;
        let cert = quinn::Certificate::from_der(&cert).map_err(|err| {
            Error::GeneralError(format!("Failed to parse certificate from file: {}", err))
        })?;
        server_config
            .certificate(quinn::CertificateChain::from_certs(vec![cert]), key)
            .map_err(|err| {
                Error::GeneralError(format!(
                    "Failed to set certificate for communication: {}",
                    err
                ))
            })?;

        let config = server_config.build();
        Ok(Self { config })
    }
// cert_base_path: Base path where to locate custom certificate authority to trust, in DER format
// idle_timeout: Optional number of millis before timing out an idle connection
Base path where to locate custom certificate authority to trust, in DER format
idle_timeout: Optional number of millis before timing out an idle connection
Base path where to locate custom certificate authority to trust in DER format idle_timeout : Optional number of millis before timing out an idle connection
pub fn new<P: AsRef<Path>>(cert_base_path: P, idle_timeout: Option<u64>) -> Result<Self> {
        let mut server_config = quinn::ServerConfig::default();
        if let Some(timeout) = idle_timeout {
            server_config.transport = Arc::new(utils::new_transport_cfg(timeout)?)
        };
        let mut server_config = quinn::ServerConfigBuilder::new(server_config);
        server_config.protocols(ALPN_QUIC_HTTP);
        let mut cert_path = PathBuf::new();
        cert_path.push(&cert_base_path);
        cert_path.push("cert.der");
        let mut key_path = PathBuf::new();
        key_path.push(&cert_base_path);
        key_path.push("key.der");
        let (cert, key) = match fs::read(&cert_path).and_then(|x| Ok((x, fs::read(&key_path)?))) {
            Ok(x) => x,
            Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
                info!("Generating self-signed certificate...");
                let cert = rcgen::generate_simple_self_signed(vec!["localhost".into()]).map_err(
                    |err| {
                        Error::GeneralError(format!(
                            "Failed to generate self-signed certificate: {}",
                            err
                        ))
                    },
                )?;
                let key = cert.serialize_private_key_der();
                let cert = cert.serialize_der().map_err(|err| {
                    Error::GeneralError(format!("Failed to serialise certificate: {}", err))
                })?;
                fs::create_dir_all(cert_base_path).map_err(|err| {
                    Error::GeneralError(format!("Failed to create certificate directory: {}", err))
                })?;
                fs::write(&cert_path, &cert).map_err(|err| {
                    Error::GeneralError(format!("Failed to write certificate: {}", err))
                })?;
                fs::write(&key_path, &key).map_err(|err| {
                    Error::GeneralError(format!("Failed to write private key: {}", err))
                })?;
                (cert, key)
            }
            Err(e) => {
                return Err(Error::GeneralError(format!(
                    "Failed to read certificate: {}",
                    e
                )));
            }
        };
        let key = quinn::PrivateKey::from_der(&key).map_err(|err| {
            Error::GeneralError(format!("Failed parse private key from file: {}", err))
        })?;
        let cert = quinn::Certificate::from_der(&cert).map_err(|err| {
            Error::GeneralError(format!("Failed to parse certificate from file: {}", err))
        })?;
        server_config
            .certificate(quinn::CertificateChain::from_certs(vec![cert]), key)
            .map_err(|err| {
                Error::GeneralError(format!(
                    "Failed to set certificate for communication: {}",
                    err
                ))
            })?;
        let config = server_config.build();
        Ok(Self { config })
    }
pub fn new < P : AsRef < Path > > ( cert_base_path : P , idle_timeout : Option < u64 > ) -> Result < Self > { let mut server_config = quinn :: ServerConfig :: default ( ) ; if let Some ( timeout ) = idle_timeout { server_config . transport = Arc :: new ( utils :: new_transport_cfg ( timeout ) ? ) } ; let mut server_config = quinn :: ServerConfigBuilder :: new ( server_config ) ; server_config . protocols ( ALPN_QUIC_HTTP ) ; let mut cert_path = PathBuf :: new ( ) ; cert_path . push ( & cert_base_path ) ; cert_path . push ( " " ) ; let mut key_path = PathBuf :: new ( ) ; key_path . push ( & cert_base_path ) ; key_path . push ( " " ) ; let ( cert , key ) = match fs :: read ( & cert_path ) . and_then ( | x | Ok ( ( x , fs :: read ( & key_path ) ? ) ) ) { Ok ( x ) => x , Err ( ref e ) if e . kind ( ) == io :: ErrorKind :: NotFound => { info ! ( " " ) ; let cert = rcgen :: generate_simple_self_signed ( vec ! [ " " into ( ) ] ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } , ) ? ; let key = cert . serialize_private_key_der ( ) ; let cert = cert . serialize_der ( ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; fs :: create_dir_all ( cert_base_path ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; fs :: write ( & cert_path , & cert ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; fs :: write ( & key_path , & key ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; ( cert , key ) } Err ( e ) => { return Err ( Error :: GeneralError ( format ! ( " " e ) ) ) ; } } ; let key = quinn :: PrivateKey :: from_der ( & key ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; let cert = quinn :: Certificate :: from_der ( & cert ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; server_config . certificate ( quinn :: CertificateChain :: from_certs ( vec ! [ cert ] ) , key ) . map_err ( | err | { Error :: GeneralError ( format ! ( " " err ) ) } ) ? ; let config = server_config . build ( ) ; Ok ( Self { config } ) }
cert_base_path: Base path where to locate custom certificate authority to trust, in DER format
idle_timeout: Optional number of millis before timing out an idle connection
cert_base_path : Base path where to locate custom certificate authority to trust in DER format idle_timeout : Optional number of millis before timing out an idle connection
cert_base_path
P
idle_timeout
Option<u64>