pub fn from_params(mut params: CertificateParams) -> Result<Self> {
        let key_pair = if let Some(key_pair) = params.key_pair.take() {
            if !key_pair.is_compatible(params.alg) {
                return Err(RcgenError::CertificateKeyPairMismatch.into());
            }
            key_pair
        } else {
            KeyPair::generate(params.alg)?
        };

        let serialized_der = key_pair.serialize_der();
        let private_key = if key_pair.is_compatible(&rcgen::PKCS_ED25519) {
            CryptoPrivateKey {
                kind: CryptoPrivateKeyKind::Ed25519(
                    Ed25519KeyPair::from_pkcs8(&serialized_der)
                        .map_err(|e| Error::new(e.to_string()))?,
                ),
                serialized_der,
            }
        } else if key_pair.is_compatible(&rcgen::PKCS_ECDSA_P256_SHA256) {
            CryptoPrivateKey {
                kind: CryptoPrivateKeyKind::Ecdsa256(
                    EcdsaKeyPair::from_pkcs8(
                        &ring::signature::ECDSA_P256_SHA256_ASN1_SIGNING,
                        &serialized_der,
                    )
                    .map_err(|e| Error::new(e.to_string()))?,
                ),
                serialized_der,
            }
        } else if key_pair.is_compatible(&rcgen::PKCS_RSA_SHA256) {
            CryptoPrivateKey {
                kind: CryptoPrivateKeyKind::Rsa256(
                    RsaKeyPair::from_pkcs8(&serialized_der)
                        .map_err(|e| Error::new(e.to_string()))?,
                ),
                serialized_der,
            }
        } else {
            return Err(Error::new("Unsupported key_pair".to_owned()));
        };
        params.key_pair = Some(key_pair);

        let expires = params.not_after.into();
        let x509_cert = rcgen::Certificate::from_params(params)?;
        let certificate = x509_cert.serialize_der()?;

        Ok(RTCCertificate {
            certificate: dtls::crypto::Certificate {
                certificate: vec![rustls::Certificate(certificate)],
                private_key,
            },
            stats_id: format!(
                "certificate-{}",
                SystemTime::now()
                    .duration_since(UNIX_EPOCH)
                    .unwrap()
                    .as_nanos() as u64
            ),
            x509_cert,
            expires,
        })
    }
/// from_params generates a new x509 compliant Certificate to be used
/// by DTLS for encrypting data sent over the wire. This method differs from
/// generate_certificate by allowing to specify a template x509.Certificate to
/// be used in order to define certificate parameters.
from_params generates a new x509 compliant Certificate to be used
by DTLS for encrypting data sent over the wire. This method differs from
generate_certificate by allowing to specify a template x509.Certificate to
be used in order to define certificate parameters.
from_params generates a new x509 compliant Certificate to be used by DTLS for encrypting data sent over the wire . This method differs from generate_certificate by allowing to specify a template x509 . Certificate to be used in order to define certificate parameters .
pub fn from_params(mut params: CertificateParams) -> Result<Self> {
        let key_pair = if let Some(key_pair) = params.key_pair.take() {
            if !key_pair.is_compatible(params.alg) {
                return Err(RcgenError::CertificateKeyPairMismatch.into());
            }
            key_pair
        } else {
            KeyPair::generate(params.alg)?
        };
        let serialized_der = key_pair.serialize_der();
        let private_key = if key_pair.is_compatible(&rcgen::PKCS_ED25519) {
            CryptoPrivateKey {
                kind: CryptoPrivateKeyKind::Ed25519(
                    Ed25519KeyPair::from_pkcs8(&serialized_der)
                        .map_err(|e| Error::new(e.to_string()))?,
                ),
                serialized_der,
            }
        } else if key_pair.is_compatible(&rcgen::PKCS_ECDSA_P256_SHA256) {
            CryptoPrivateKey {
                kind: CryptoPrivateKeyKind::Ecdsa256(
                    EcdsaKeyPair::from_pkcs8(
                        &ring::signature::ECDSA_P256_SHA256_ASN1_SIGNING,
                        &serialized_der,
                    )
                    .map_err(|e| Error::new(e.to_string()))?,
                ),
                serialized_der,
            }
        } else if key_pair.is_compatible(&rcgen::PKCS_RSA_SHA256) {
            CryptoPrivateKey {
                kind: CryptoPrivateKeyKind::Rsa256(
                    RsaKeyPair::from_pkcs8(&serialized_der)
                        .map_err(|e| Error::new(e.to_string()))?,
                ),
                serialized_der,
            }
        } else {
            return Err(Error::new("Unsupported key_pair".to_owned()));
        };
        params.key_pair = Some(key_pair);
        let expires = params.not_after.into();
        let x509_cert = rcgen::Certificate::from_params(params)?;
        let certificate = x509_cert.serialize_der()?;
        Ok(RTCCertificate {
            certificate: dtls::crypto::Certificate {
                certificate: vec![rustls::Certificate(certificate)],
                private_key,
            },
            stats_id: format!(
                "certificate-{}",
                SystemTime::now()
                    .duration_since(UNIX_EPOCH)
                    .unwrap()
                    .as_nanos() as u64
            ),
            x509_cert,
            expires,
        })
    }
pub fn from_params ( mut params : CertificateParams ) -> Result < Self > { let key_pair = if let Some ( key_pair ) = params . key_pair . take ( ) { if ! key_pair . is_compatible ( params . alg ) { return Err ( RcgenError :: CertificateKeyPairMismatch . into ( ) ) ; } key_pair } else { KeyPair :: generate ( params . alg ) ? } ; let serialized_der = key_pair . serialize_der ( ) ; let private_key = if key_pair . is_compatible ( & rcgen :: PKCS_ED25519 ) { CryptoPrivateKey { kind : CryptoPrivateKeyKind :: Ed25519 ( Ed25519KeyPair :: from_pkcs8 ( & serialized_der ) . map_err ( | e | Error :: new ( e . to_string ( ) ) ) ? , ) , serialized_der , } } else if key_pair . is_compatible ( & rcgen :: PKCS_ECDSA_P256_SHA256 ) { CryptoPrivateKey { kind : CryptoPrivateKeyKind :: Ecdsa256 ( EcdsaKeyPair :: from_pkcs8 ( & ring :: signature :: ECDSA_P256_SHA256_ASN1_SIGNING , & serialized_der , ) . map_err ( | e | Error :: new ( e . to_string ( ) ) ) ? , ) , serialized_der , } } else if key_pair . is_compatible ( & rcgen :: PKCS_RSA_SHA256 ) { CryptoPrivateKey { kind : CryptoPrivateKeyKind :: Rsa256 ( RsaKeyPair :: from_pkcs8 ( & serialized_der ) . map_err ( | e | Error :: new ( e . to_string ( ) ) ) ? , ) , serialized_der , } } else { return Err ( Error :: new ( " " . to_owned ( ) ) ) ; } ; params . key_pair = Some ( key_pair ) ; let expires = params . not_after . into ( ) ; let x509_cert = rcgen :: Certificate :: from_params ( params ) ? ; let certificate = x509_cert . serialize_der ( ) ? ; Ok ( RTCCertificate { certificate : dtls :: crypto :: Certificate { certificate : vec ! [ rustls Certificate ( certificate ) ] , private_key , } , stats_id : format ! ( " " SystemTime now ( ) duration_since ( UNIX_EPOCH ) unwrap ( ) as_nanos ( ) as u64 ) , x509_cert , expires , } ) }
from_params generates a new x509 compliant Certificate to be used
by DTLS for encrypting data sent over the wire.
from_params generates a new x509 compliant Certificate to be used by DTLS for encrypting data sent over the wire .
params
CertificateParams