Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify test chain building #244

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions src/verify_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,37 +1077,33 @@ mod tests {
chain_length: usize,
all_same_subject: bool,
) -> IntermediateChain {
let mut intermediates: Vec<CertifiedKey> = Vec::with_capacity(chain_length);
let mut chain = Vec::with_capacity(chain_length);

let mut prev = None;
for i in 0..chain_length {
let (issuer, issuer_key) = if i == 0 {
(&ca_cert.cert, &ca_cert.key_pair)
} else {
(&intermediates[i - 1].cert, &intermediates[i - 1].key_pair)
let issuer = match &prev {
Some(prev) => prev,
None => ca_cert,
};

let intermediate = issuer_params(match all_same_subject {
true => "Bogus Subject".to_string(),
false => format!("Bogus Subject {i}"),
});
let intermediate_key_pair =
KeyPair::generate_for(test_utils::RCGEN_SIGNATURE_ALG).unwrap();
let intermediate = intermediate
.signed_by(&intermediate_key_pair, issuer, issuer_key)

let key_pair = KeyPair::generate_for(test_utils::RCGEN_SIGNATURE_ALG).unwrap();
let cert = intermediate
.signed_by(&key_pair, &issuer.cert, &issuer.key_pair)
.unwrap();
intermediates.push(CertifiedKey {
cert: intermediate,
key_pair: intermediate_key_pair,
});
}

let last_issuer = intermediates.pop().unwrap();
let mut chain = intermediates
.into_iter()
.map(|cert_and_key| cert_and_key.cert.into())
.collect::<Vec<_>>();
chain.push(last_issuer.cert.der().clone());
chain.push(cert.der().clone());
prev = Some(CertifiedKey { cert, key_pair });
}

IntermediateChain { last_issuer, chain }
IntermediateChain {
last_issuer: prev.unwrap(),
chain,
}
}

struct IntermediateChain {
Expand Down
Loading