Skip to content

Commit

Permalink
Avoid insert(0), it's O(n^2) when done repeatedly (#10051)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Dec 23, 2023
1 parent 4e839cc commit 74cb05b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/rust/cryptography-x509-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'a, 'chain, B: CryptoOps> ChainBuilder<'a, 'chain, B> {
)?,
) {
Ok(mut chain) => {
chain.insert(0, working_cert.clone());
chain.push(working_cert.clone());
return Ok(chain);
}
Err(e) => last_err = Some(e),
Expand Down Expand Up @@ -334,11 +334,14 @@ impl<'a, 'chain, B: CryptoOps> ChainBuilder<'a, 'chain, B> {

self.policy.permits_ee(leaf, &leaf_extensions)?;

self.build_chain_inner(
let mut chain = self.build_chain_inner(
leaf,
0,
&leaf_extensions,
NameChain::new(None, &leaf_extensions, false)?,
)
)?;
// We build the chain in reverse order, fix it now.
chain.reverse();
Ok(chain)
}
}

0 comments on commit 74cb05b

Please sign in to comment.