pub fn new() -> Result<Ca, Box<dyn Error>> {
        let dir = tempfile::tempdir()?;
        let rsa = Rsa::generate(2048)?;
        let pkey = PKey::from_rsa(rsa)?;
        let name = {
            let mut builder = X509NameBuilder::new()?;
            builder.append_entry_by_nid(Nid::COMMONNAME, "test ca")?;
            builder.build()
        };
        let cert = {
            let mut builder = X509::builder()?;
            builder.set_version(2)?;
            builder.set_pubkey(&pkey)?;
            builder.set_issuer_name(&name)?;
            builder.set_subject_name(&name)?;
            builder.set_not_before(&*Asn1Time::days_from_now(0)?)?;
            builder.set_not_after(&*Asn1Time::days_from_now(365)?)?;
            builder.append_extension(BasicConstraints::new().critical().ca().build()?)?;
            builder.sign(&pkey, MessageDigest::sha256())?;
            builder.build()
        };
        fs::write(dir.path().join("ca.crt"), &cert.to_pem()?)?;
        Ok(Ca { dir, cert, pkey })
    }
/// Constructs a new certificate authority.
Constructs a new certificate authority.
Constructs a new certificate authority .
pub fn new() -> Result<Ca, Box<dyn Error>> {
        let dir = tempfile::tempdir()?;
        let rsa = Rsa::generate(2048)?;
        let pkey = PKey::from_rsa(rsa)?;
        let name = {
            let mut builder = X509NameBuilder::new()?;
            builder.append_entry_by_nid(Nid::COMMONNAME, "test ca")?;
            builder.build()
        };
        let cert = {
            let mut builder = X509::builder()?;
            builder.set_version(2)?;
            builder.set_pubkey(&pkey)?;
            builder.set_issuer_name(&name)?;
            builder.set_subject_name(&name)?;
            builder.set_not_before(&*Asn1Time::days_from_now(0)?)?;
            builder.set_not_after(&*Asn1Time::days_from_now(365)?)?;
            builder.append_extension(BasicConstraints::new().critical().ca().build()?)?;
            builder.sign(&pkey, MessageDigest::sha256())?;
            builder.build()
        };
        fs::write(dir.path().join("ca.crt"), &cert.to_pem()?)?;
        Ok(Ca { dir, cert, pkey })
    }
pub fn new ( ) -> Result < Ca , Box < dyn Error > > { let dir = tempfile :: tempdir ( ) ? ; let rsa = Rsa :: generate ( 2048 ) ? ; let pkey = PKey :: from_rsa ( rsa ) ? ; let name = { let mut builder = X509NameBuilder :: new ( ) ? ; builder . append_entry_by_nid ( Nid :: COMMONNAME , " " ) ? ; builder . build ( ) } ; let cert = { let mut builder = X509 :: builder ( ) ? ; builder . set_version ( 2 ) ? ; builder . set_pubkey ( & pkey ) ? ; builder . set_issuer_name ( & name ) ? ; builder . set_subject_name ( & name ) ? ; builder . set_not_before ( & * Asn1Time :: days_from_now ( 0 ) ? ) ? ; builder . set_not_after ( & * Asn1Time :: days_from_now ( 365 ) ? ) ? ; builder . append_extension ( BasicConstraints :: new ( ) . critical ( ) . ca ( ) . build ( ) ? ) ? ; builder . sign ( & pkey , MessageDigest :: sha256 ( ) ) ? ; builder . build ( ) } ; fs :: write ( dir . path ( ) . join ( " " ) , & cert . to_pem ( ) ? ) ? ; Ok ( Ca { dir , cert , pkey } ) }
Constructs a new certificate authority.
Constructs a new certificate authority .