Skip to content

Commit 6964132

Browse files
authored
x509-cert: fixup Arbitrary for certificates (#1150)
Fixes #1149 This broke with the parsing profiles (#987)
1 parent 5b477c3 commit 6964132

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

x509-cert/src/certificate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ pub trait Profile: PartialEq + Debug + Eq + Clone {
3131
}
3232
}
3333

34+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
3435
#[derive(Debug, PartialEq, Eq, Clone)]
3536
/// Parse certificates with rfc5280-compliant checks
3637
pub struct Rfc5280;
3738

3839
impl Profile for Rfc5280 {}
3940

4041
#[cfg(feature = "hazmat")]
42+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
4143
#[derive(Debug, PartialEq, Eq, Clone)]
4244
/// Parse raw x509 certificate and disable all the checks
4345
pub struct Raw;

x509-cert/tests/certificate.rs

+19
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,22 @@ fn load_certificate_chains() {
446446

447447
assert_eq!(chain.len(), 4, "4 certificates are expected in this chain");
448448
}
449+
450+
#[cfg(feature = "arbitrary")]
451+
#[test]
452+
// Purpose of this check is to ensure the arbitraty trait is provided for certificate variants
453+
#[allow(unused)]
454+
fn certificate_arbitrary() {
455+
fn check_arbitrary<'a>(_arbitrary: impl arbitrary::Arbitrary<'a>) {}
456+
457+
fn check_certificate(certificate: x509_cert::Certificate) {
458+
check_arbitrary(certificate);
459+
}
460+
461+
#[cfg(feature = "hazmat")]
462+
fn check_raw_certificate(
463+
certificate: x509_cert::certificate::CertificateInner<x509_cert::certificate::Raw>,
464+
) {
465+
check_arbitrary(certificate);
466+
}
467+
}

0 commit comments

Comments
 (0)