forked from rustls/webpki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tests to end_entity.rs, factor out test utils
As suggested by @cpu in this comment thread: rustls#169 (comment)
- Loading branch information
Showing
5 changed files
with
107 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#[cfg(feature = "alloc")] | ||
use crate::types::CertificateDer; | ||
|
||
/// Signature algorithm used by certificates generated using `make_issuer` and | ||
/// `make_end_entity`. This is exported as a constant so that tests can use the | ||
/// same algorithm when generating certificates using `rcgen`. | ||
#[cfg(feature = "alloc")] | ||
pub(crate) static RCGEN_SIGNATURE_ALG: &rcgen::SignatureAlgorithm = &rcgen::PKCS_ECDSA_P256_SHA256; | ||
|
||
#[cfg(feature = "alloc")] | ||
pub(crate) fn make_issuer( | ||
org_name: impl Into<String>, | ||
name_constraints: Option<rcgen::NameConstraints>, | ||
) -> rcgen::Certificate { | ||
let mut ca_params = rcgen::CertificateParams::new(Vec::new()); | ||
ca_params | ||
.distinguished_name | ||
.push(rcgen::DnType::OrganizationName, org_name); | ||
ca_params.is_ca = rcgen::IsCa::Ca(rcgen::BasicConstraints::Unconstrained); | ||
ca_params.key_usages = vec![ | ||
rcgen::KeyUsagePurpose::KeyCertSign, | ||
rcgen::KeyUsagePurpose::DigitalSignature, | ||
rcgen::KeyUsagePurpose::CrlSign, | ||
]; | ||
ca_params.alg = RCGEN_SIGNATURE_ALG; | ||
ca_params.name_constraints = name_constraints; | ||
rcgen::Certificate::from_params(ca_params).unwrap() | ||
} | ||
|
||
#[cfg(feature = "alloc")] | ||
pub(crate) fn make_end_entity(issuer: &rcgen::Certificate) -> CertificateDer<'static> { | ||
let mut ee_params = rcgen::CertificateParams::new(vec!["example.com".to_string()]); | ||
ee_params.is_ca = rcgen::IsCa::ExplicitNoCa; | ||
ee_params.alg = &RCGEN_SIGNATURE_ALG; | ||
CertificateDer::from( | ||
rcgen::Certificate::from_params(ee_params) | ||
.unwrap() | ||
.serialize_der_with_signer(issuer) | ||
.unwrap(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters