Skip to content

Commit

Permalink
x509-cert: fixup Arbitrary for certificates (RustCrypto#1150)
Browse files Browse the repository at this point in the history
Fixes RustCrypto#1149

This broke with the parsing profiles (RustCrypto#987)
  • Loading branch information
baloo authored Jul 12, 2023
1 parent 5b477c3 commit 6964132
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions x509-cert/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ pub trait Profile: PartialEq + Debug + Eq + Clone {
}
}

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

impl Profile for Rfc5280 {}

#[cfg(feature = "hazmat")]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, PartialEq, Eq, Clone)]
/// Parse raw x509 certificate and disable all the checks
pub struct Raw;
Expand Down
19 changes: 19 additions & 0 deletions x509-cert/tests/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,22 @@ fn load_certificate_chains() {

assert_eq!(chain.len(), 4, "4 certificates are expected in this chain");
}

#[cfg(feature = "arbitrary")]
#[test]
// Purpose of this check is to ensure the arbitraty trait is provided for certificate variants
#[allow(unused)]
fn certificate_arbitrary() {
fn check_arbitrary<'a>(_arbitrary: impl arbitrary::Arbitrary<'a>) {}

fn check_certificate(certificate: x509_cert::Certificate) {
check_arbitrary(certificate);
}

#[cfg(feature = "hazmat")]
fn check_raw_certificate(
certificate: x509_cert::certificate::CertificateInner<x509_cert::certificate::Raw>,
) {
check_arbitrary(certificate);
}
}

0 comments on commit 6964132

Please sign in to comment.