Skip to content

Commit

Permalink
Expose algorithm field on PublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
rickvanprim authored and est31 committed Jun 30, 2024
1 parent dd54046 commit 00040fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions rcgen/src/csr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions rcgen/tests/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 00040fb

Please sign in to comment.