Skip to content

Commit

Permalink
verify_cert: pull out make_end_entity test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cpu committed Sep 12, 2023
1 parent 5ea1d89 commit eb07f2f
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/verify_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,6 @@ mod tests {
use crate::ECDSA_P256_SHA256;
use crate::{EndEntityCert, Time};

let alg = &rcgen::PKCS_ECDSA_P256_SHA256;

let ca_cert = make_issuer("Bogus Subject");
let ca_cert_der = ca_cert.serialize_der().unwrap();

Expand All @@ -463,15 +461,10 @@ mod tests {
issuer = intermediate;
}

let mut ee_params = rcgen::CertificateParams::new(vec!["example.com".to_string()]);
ee_params.is_ca = rcgen::IsCa::ExplicitNoCa;
ee_params.alg = alg;
let ee_cert = rcgen::Certificate::from_params(ee_params).unwrap();
let ee_cert_der = ee_cert.serialize_der_with_signer(&issuer).unwrap();

let ee_cert_der = make_end_entity(&issuer);
let cert = EndEntityCert::try_from(&ee_cert_der[..]).unwrap();
let anchors = &[TrustAnchor::try_from_cert_der(&ca_cert_der).unwrap()];
let time = Time::from_seconds_since_unix_epoch(0x1fed_f00d);
let cert = EndEntityCert::try_from(&ee_cert_der[..]).unwrap();
let mut intermediate_certs = intermediates.iter().map(|x| x.as_ref()).collect::<Vec<_>>();

if let TrustAnchorIsActualIssuer::No = trust_anchor_is_actual_issuer {
Expand Down Expand Up @@ -512,8 +505,6 @@ mod tests {
use crate::ECDSA_P256_SHA256;
use crate::{EndEntityCert, Time};

let alg = &rcgen::PKCS_ECDSA_P256_SHA256;

let ca_cert = make_issuer(format!("Bogus Subject {chain_length}"));
let ca_cert_der = ca_cert.serialize_der().unwrap();

Expand All @@ -526,15 +517,10 @@ mod tests {
issuer = intermediate;
}

let mut ee_params = rcgen::CertificateParams::new(vec!["example.com".to_string()]);
ee_params.is_ca = rcgen::IsCa::ExplicitNoCa;
ee_params.alg = alg;
let ee_cert = rcgen::Certificate::from_params(ee_params).unwrap();
let ee_cert_der = ee_cert.serialize_der_with_signer(&issuer).unwrap();

let ee_cert_der = make_end_entity(&issuer);
let cert = EndEntityCert::try_from(&ee_cert_der[..]).unwrap();
let anchors = &[TrustAnchor::try_from_cert_der(&ca_cert_der).unwrap()];
let time = Time::from_seconds_since_unix_epoch(0x1fed_f00d);
let cert = EndEntityCert::try_from(&ee_cert_der[..]).unwrap();
let intermediates_der = intermediates.iter().map(|x| x.as_ref()).collect::<Vec<_>>();

build_chain(
Expand Down Expand Up @@ -581,4 +567,16 @@ mod tests {
ca_params.alg = &rcgen::PKCS_ECDSA_P256_SHA256;
rcgen::Certificate::from_params(ca_params).unwrap()
}

#[cfg(feature = "alloc")]
fn make_end_entity(issuer: &rcgen::Certificate) -> Vec<u8> {
let mut ee_params = rcgen::CertificateParams::new(vec!["example.com".to_string()]);
ee_params.is_ca = rcgen::IsCa::ExplicitNoCa;
ee_params.alg = &rcgen::PKCS_ECDSA_P256_SHA256;

rcgen::Certificate::from_params(ee_params)
.unwrap()
.serialize_der_with_signer(issuer)
.unwrap()
}
}

0 comments on commit eb07f2f

Please sign in to comment.