diff --git a/rcgen/src/csr.rs b/rcgen/src/csr.rs index 90ec2237..e79e21eb 100644 --- a/rcgen/src/csr.rs +++ b/rcgen/src/csr.rs @@ -19,6 +19,13 @@ pub struct PublicKey { alg: &'static SignatureAlgorithm, } +impl PublicKey { + /// The algorithm used to generate the public key and sign the CSR. + pub fn algorithm(&self) -> &SignatureAlgorithm { + self.alg + } +} + impl PublicKeyData for PublicKey { fn alg(&self) -> &SignatureAlgorithm { self.alg diff --git a/rcgen/tests/generic.rs b/rcgen/tests/generic.rs index 3d5075b8..0af46b17 100644 --- a/rcgen/tests/generic.rs +++ b/rcgen/tests/generic.rs @@ -364,13 +364,15 @@ mod test_csr { #[test] fn test_csr_roundtrip() { + let key_pair = KeyPair::generate().unwrap(); + // We should be able to serialize a CSR, and then parse the CSR. - _ = CertificateSigningRequestParams::from_der( - CertificateParams::default() - .serialize_request(&KeyPair::generate().unwrap()) - .unwrap() - .der(), - ) - .unwrap(); + let csr = CertificateParams::default() + .serialize_request(&key_pair) + .unwrap(); + let csrp = CertificateSigningRequestParams::from_der(csr.der()).unwrap(); + + // Ensure algorithms match. + assert_eq!(key_pair.algorithm(), csrp.public_key.algorithm()); } }