Skip to content

add Certificate.from_pem and Certificate.from_der#387

Closed
Aurvandill wants to merge 3 commits intorustls:mainfrom
Aurvandill:main
Closed

add Certificate.from_pem and Certificate.from_der#387
Aurvandill wants to merge 3 commits intorustls:mainfrom
Aurvandill:main

Conversation

@Aurvandill
Copy link

This adds the two requested functions from #274.

@djc
Copy link
Member

djc commented Oct 8, 2025

I don't think this makes sense. What are you trying to do that the 0.14.x API does not let you do today?

@Aurvandill
Copy link
Author

I'm trying to read in a certificate which is pem encoded to sign something later on. I could use an Issuer::from_ca_cert_pem to load the cert as well but i wan't to display the cert for confirmation before loading the key.
Also since the mentioned issue was still open I guessed it was still needed.

@Aurvandill
Copy link
Author

Aurvandill commented Oct 8, 2025

It would have also been nice to be able to do something like

let cert = Certificate::from_pem(pem_bytes);
let (_, x509_cert) = X509Certificate::from_der(certificate.der())?;
println!("{:?}", x509_cert.tbs_certificate.validity)

Or is there perhaps another way to get CertificateParams from a pem file?

@djc
Copy link
Member

djc commented Oct 9, 2025

Since 0.14, we no longer support getting a CertificateParams from DER or PEM, because we want to avoid API that allows round-tripping certificates -- potentially with surprising results. If there are things you want to display, suggest parsing it separately (we recommend using the x509-parser crate for this).

@djc djc closed this Oct 9, 2025
@Aurvandill
Copy link
Author

thanks for the info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants