Skip to content

Commit 67a73a7

Browse files
committed
Move Certificate::key_identifier() to CertificateParams
1 parent bcfcba0 commit 67a73a7

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

rcgen/src/certificate.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::{
2525
#[derive(Debug, Clone)]
2626
pub struct Certificate {
2727
pub(crate) params: CertificateParams,
28-
pub(crate) subject_public_key_info: Vec<u8>,
2928
pub(crate) der: CertificateDer<'static>,
3029
}
3130

@@ -34,13 +33,6 @@ impl Certificate {
3433
pub fn params(&self) -> &CertificateParams {
3534
&self.params
3635
}
37-
/// Calculates a subject key identifier for the certificate subject's public key.
38-
/// This key identifier is used in the SubjectKeyIdentifier X.509v3 extension.
39-
pub fn key_identifier(&self) -> Vec<u8> {
40-
self.params
41-
.key_identifier_method
42-
.derive(&self.subject_public_key_info)
43-
}
4436
/// Get the certificate in DER encoded format.
4537
///
4638
/// [`CertificateDer`] implements `Deref<Target = [u8]>` and `AsRef<[u8]>`, so you can easily
@@ -169,11 +161,7 @@ impl CertificateParams {
169161
};
170162

171163
let der = self.serialize_der_with_signer(public_key, issuer)?;
172-
Ok(Certificate {
173-
params: self,
174-
subject_public_key_info: public_key.subject_public_key_info(),
175-
der,
176-
})
164+
Ok(Certificate { params: self, der })
177165
}
178166

179167
/// Generates a new self-signed certificate from the given parameters.
@@ -188,13 +176,15 @@ impl CertificateParams {
188176
key_pair,
189177
};
190178

191-
let subject_public_key_info = key_pair.subject_public_key_info();
192179
let der = self.serialize_der_with_signer(key_pair, issuer)?;
193-
Ok(Certificate {
194-
params: self,
195-
subject_public_key_info,
196-
der,
197-
})
180+
Ok(Certificate { params: self, der })
181+
}
182+
183+
/// Calculates a subject key identifier for the certificate subject's public key.
184+
/// This key identifier is used in the SubjectKeyIdentifier X.509v3 extension.
185+
pub fn key_identifier(&self, key: &impl PublicKeyData) -> Vec<u8> {
186+
self.key_identifier_method
187+
.derive(&key.subject_public_key_info())
198188
}
199189

200190
/// Parses an existing ca certificate from the ASCII PEM format.
@@ -1489,8 +1479,9 @@ PITGdT9dgN88nHPCle0B1+OY+OZ5
14891479
);
14901480

14911481
let ca_kp = KeyPair::from_pem(ca_key).unwrap();
1482+
let key_id = params.key_identifier(&ca_kp);
14921483
let ca_cert = params.self_signed(&ca_kp).unwrap();
1493-
assert_eq!(&ca_ski, &ca_cert.key_identifier());
1484+
assert_eq!(&ca_ski, &key_id);
14941485

14951486
let (_, x509_ca) = x509_parser::parse_x509_certificate(ca_cert.der()).unwrap();
14961487
assert_eq!(

rcgen/src/csr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ impl CertificateSigningRequestParams {
218218

219219
Ok(Certificate {
220220
params: self.params,
221-
subject_public_key_info: self.public_key.subject_public_key_info(),
222221
der,
223222
})
224223
}

0 commit comments

Comments
 (0)