4.5 KiB
Rcgen 0.12 to 0.13 Migration Guide
This document is a meant to be a helpful guide for some of the API changes made between rcgen 0.12 and 0.13. For information on other changes in 0.13 see [rcgen/CHANGELOG.md].
Key Pairs
-
Previously it was possible to have certificate generation automatically create a subject
KeyPairfor you by leaving thekey_pairfield ofCertificateParamsempty, and retrieving the generatedKeyPairfrom aCertificatecreated with theCertificateParamsby callingCertificate::get_key_pair().To offer more consistency and to keep the
CertificateParamsandCertificatetypes from holding private key data, the new API requires you handleKeyPaircreation yourself. SeeCertifiedKey,KeyPair::generate(),KeyPair::generate_for()andKeyPair::generate_rsa_for()for more information. -
Serializing a
Certificate'sKeyPairto DER or PEM was previously done by callingCertificate::serialize_private_key_der()orCertificate::serialize_private_key_pem(). This is now handled by callingKeyPair::serialize_der()orKeyPair::serialize_pem().
Certificates
-
For quick-and-easy self-signed certificate issuance,
generate_simple_self_signednow returns aCertifiedKeyin the success case instead of aCertificate. The self-signedCertificatecan be accessed in thecertfield ofCertifiedKey, and the generated subject key pair inkey_pair. -
Custom self-signed certificate issuance was previously done by constructing
CertificateParamsand callingCertificate::from_params()to create aCertificate. This is now done by callingCertificateParams::self_signed(), providing a subjectKeyPairof your choosing. -
Custom certificate issuance signed by an issuer was previously done by constructing
CertificateParams, callingCertificate::from_params()and then choosing the issuer at serialization time. This is now done ahead of serialization by callingCertificateParams::signed_by()and providing a subjectKeyPairas well as an issuerCertificateandKeyPair. -
Previously certificate serialization was done by calling
Certificate::serialize_der(),Certificate::serialize_pem(),Certificate::serialize_der_with_signer()orCertificate::serialize_pem_with_signer(). Each time a serialization fn was called a new certificate was issued, leading to confusion when it was desired to serialize the same certificate in two formats. In the new API issuance is handled byCertificateParamsfns and the generatedCertificatewill not change when serialized. You can serialize it to PEM by callingCertificate::pem(), or access the DER encoding by callingCertificate::der().
Certificate Signing Requests (CSRs)
-
Previously it was only possible to create a new CSR by first issuing a
CertificatefromCertificateParams, and callingCertificate::serialize_request_pem()orCertificate::serialize_request_der(). In the updated API you can create aCertificateSigningRequestdirectly fromCertificateParamsby callingCertificateParams::serialize_requestand providing a subjectKeyPair. You may serialize the CSR to DER or PEM by callingCertificateSigningRequest::der()orCertificateSingingRequest::pem(). -
To load a CSR from an existing PEM/DER copy with the old API required calling
CertificateSingingRequest::from_pem()orCertificateSigningRequest::from_der(). The new API introduces aCertificateSingingRequestParamstype that can be created usingCertificateSigningRequestParams::from_pem()orCertificateSingingRequest::from_der(). -
To issue a certificate from an existing CSR with the old API required calling
CertificateSigningRequest::serialize_der_with_signer()orCertificateSigningRequest::serialize_pem_with_signer(). In the new API, callCertificateSigningRequestParams::signed_by()and provide an issuerCertificateandKeyPair.
Certificate Revocation Lists (CRLs)
-
Previously a
CertificateRevocationListwas created by callingCertificateRevocationList::from_params(). This is now done by callingCertificateRevocationListParams::signed_by()and providing an issuerCertificateandKeyPair. -
Previously a created
CertificateRevocationListcould be serialized to DER or PEM by callingCertificateRevocationList::serialize_der_with_signer()orCertificateRevocationList::serialize_pem_with_signer(). This is now done by callingCertificateRevocationList::der()orCertificateRevocationList::pem().