mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-10 13:35:21 +00:00
fix(automation): sign_trust deduplicates certificates with a set
Each imported certificate was compared with every one already collected, quadratic in a bundle of many distinct certificates.
This commit is contained in:
@@ -309,6 +309,9 @@ impl Automation {
|
||||
pub(crate) fn sign_trust(&mut self, a: &Args) -> Result<Value> {
|
||||
let mut certs: Vec<Certificate> =
|
||||
if a.opt_bool("clear")?.unwrap_or(false) { Vec::new() } else { self.session.trusted_certificates().to_vec() };
|
||||
// Which certificates are already in, by their bytes: a set, so a bundle of many distinct
|
||||
// certificates isn't compared against every one before it.
|
||||
let mut known: std::collections::HashSet<Vec<u8>> = certs.iter().map(|c| c.raw.clone()).collect();
|
||||
let paths: Vec<String> = match a.get("paths") {
|
||||
None => Vec::new(),
|
||||
Some(v) => v
|
||||
@@ -329,7 +332,7 @@ impl Automation {
|
||||
sign::x509::load_certificates(&bytes).map_err(failed)?
|
||||
};
|
||||
for c in found {
|
||||
if !certs.iter().any(|t| t.raw == c.raw) {
|
||||
if known.insert(c.raw.clone()) {
|
||||
certs.push(c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user