Skip to content

Commit 41d768e

Browse files
committed
x509-cert: use type aliases
1 parent a495f6f commit 41d768e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

x509-cert/src/certificate.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ impl<P: Profile> TbsCertificate<P> {
170170
}
171171
}
172172

173+
/// X.509 certificates are defined in [RFC 5280 Section 4.1].
174+
///
175+
/// [RFC 5280 Section 4.1]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.1
176+
pub type Certificate = CertificateInner<Rfc5280>;
177+
173178
/// X.509 certificates are defined in [RFC 5280 Section 4.1].
174179
///
175180
/// ```text
@@ -184,14 +189,14 @@ impl<P: Profile> TbsCertificate<P> {
184189
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
185190
#[derive(Clone, Debug, Eq, PartialEq, Sequence, ValueOrd)]
186191
#[allow(missing_docs)]
187-
pub struct Certificate<P: Profile = Rfc5280> {
192+
pub struct CertificateInner<P: Profile = Rfc5280> {
188193
pub tbs_certificate: TbsCertificate<P>,
189194
pub signature_algorithm: AlgorithmIdentifierOwned,
190195
pub signature: BitString,
191196
}
192197

193198
#[cfg(feature = "pem")]
194-
impl<P: Profile> PemLabel for Certificate<P> {
199+
impl<P: Profile> PemLabel for CertificateInner<P> {
195200
const PEM_LABEL: &'static str = "CERTIFICATE";
196201
}
197202

x509-cert/tests/certificate.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use x509_cert::Certificate;
1212
use x509_cert::*;
1313

1414
#[cfg(feature = "pem")]
15-
use der::{pem::LineEnding, DecodePem, EncodePem};
15+
use der::DecodePem;
1616

1717
// TODO - parse and compare extension values
1818
const EXTENSIONS: &[(&str, bool)] = &[
@@ -403,7 +403,7 @@ fn decode_cert() {
403403
fn decode_cert_negative_serial_number() {
404404
let der_encoded_cert = include_bytes!("examples/28903a635b5280fae6774c0b6da7d6baa64af2e8.der");
405405

406-
let cert = Certificate::<Rfc5280>::from_der(der_encoded_cert).unwrap();
406+
let cert = Certificate::from_der(der_encoded_cert).unwrap();
407407
assert_eq!(
408408
cert.tbs_certificate.serial_number.as_bytes(),
409409
// INTEGER (125 bit) -2.370157924795571e+37
@@ -417,11 +417,14 @@ fn decode_cert_negative_serial_number() {
417417
#[cfg(all(feature = "pem", feature = "hazmat"))]
418418
#[test]
419419
fn decode_cert_overlength_serial_number() {
420+
use der::{pem::LineEnding, DecodePem, EncodePem};
421+
use x509_cert::certificate::CertificateInner;
422+
420423
let pem_encoded_cert = include_bytes!("examples/qualcomm.pem");
421424

422-
assert!(Certificate::<Rfc5280>::from_pem(pem_encoded_cert).is_err());
425+
assert!(Certificate::from_pem(pem_encoded_cert).is_err());
423426

424-
let cert = Certificate::<x509_cert::certificate::Raw>::from_pem(pem_encoded_cert).unwrap();
427+
let cert = CertificateInner::<x509_cert::certificate::Raw>::from_pem(pem_encoded_cert).unwrap();
425428
assert_eq!(
426429
cert.tbs_certificate.serial_number.as_bytes(),
427430
&[

0 commit comments

Comments
 (0)