From 1982366e08c091ad4800290e525e584165d14ef4 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Thu, 29 Feb 2024 11:44:46 +0100 Subject: [PATCH] Improve sq network fetch output. - Call `best_effort_primary_uid` after inserting the certificate into the certificate store. Otherwise, `best_effort_primary_uid` won't be able to take any new authentication information into account. - Sort the certificates by the degree to which we can authenticate them. --- src/commands/network.rs | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/commands/network.rs b/src/commands/network.rs index eacc01f4..dbb1c83a 100644 --- a/src/commands/network.rs +++ b/src/commands/network.rs @@ -100,31 +100,40 @@ pub fn import_certs(config: &Config, certs: Vec) -> Result<()> { return Ok(()); } - let certs = merge_keyring(certs)?.into_values() - .map(|cert| { - let fpr = cert.fingerprint(); - let userid = - best_effort_primary_uid( - Some(&config), &cert, config.policy, config.time); - - (fpr, userid, cert) - }) - .collect::>(); - let cert_store = config.cert_store_or_else() .context("Inserting results")?; let mut stats = cert_store::store::MergePublicCollectStats::new(); + let certs = merge_keyring(certs)?.into_values().collect::>(); + wprintln!("\nImporting {} into the certificate store:\n", certs.len().of("certificate")); - for (i, (fpr, sanitized_userid, cert)) in certs.into_iter().enumerate() { - cert_store.update_by(Arc::new(cert.into()), &mut stats) + for cert in certs.iter() { + cert_store.update_by(Arc::new(cert.clone().into()), &mut stats) .with_context(|| { - format!("Inserting {}, {}", fpr, sanitized_userid) + let sanitized_userid = best_effort_primary_uid( + Some(&config), &cert, config.policy, config.time); + + format!("Inserting {}, {}", + cert.fingerprint(), sanitized_userid) })?; - wprintln!(" {}. {} {}", i + 1, fpr, sanitized_userid); + } + + let mut certs = certs.into_iter() + .map(|cert| { + let userid = best_effort_primary_uid( + Some(&config), &cert, config.policy, config.time); + (userid, cert) + }) + .collect::>(); + + // Reverse sort, i.e., most authenticated first. + certs.sort_unstable_by_key(|cert| usize::MAX - cert.0.trust_amount()); + + for (i, (userid, cert)) in certs.into_iter().enumerate() { + wprintln!(" {}. {} {}", i + 1, cert.fingerprint(), userid); } wprintln!("\nImported {}, updated {}, {} unchanged, {}.",