Improve error handling opening the cert store.

- Improvements similar to the one in the previous commit.

  - See #492.
This commit is contained in:
Justus Winter 2024-12-14 17:09:49 +01:00
parent 5adb325f88
commit 90cb8d4ef2
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
3 changed files with 17 additions and 12 deletions

View File

@ -927,6 +927,8 @@ pub fn dispatch_search(mut sq: Sq, c: cli::network::search::Command)
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async {
for _ in 0..iterations {
let cert_store = sq.cert_store()?;
let mut requests = JoinSet::new();
let mut converged = true;
std::mem::take(&mut queries).into_iter().for_each(|query| {
@ -1024,7 +1026,7 @@ pub fn dispatch_search(mut sq: Sq, c: cli::network::search::Command)
// Finally, we also consult the certificate store to
// discover more identifiers. This is sync, but we use
// the same mechanism to merge the result back in.
if let Ok(Some(store)) = sq.cert_store() {
if let Some(store) = &cert_store {
pb.inc_length(1);
let mut email_query = UserIDQueryParams::new();
email_query.set_email(true);

View File

@ -181,7 +181,7 @@ impl<'c, 'store, 'rstore> VHelper<'c, 'store, 'rstore> {
}
}
fn print_sigs(&mut self, results: &[VerificationResult]) {
fn print_sigs(&mut self, results: &[VerificationResult]) -> Result<()> {
make_qprintln!(self.quiet);
use crate::common::pki::output::print_path;
use crate::print_error_chain;
@ -265,7 +265,7 @@ impl<'c, 'store, 'rstore> VHelper<'c, 'store, 'rstore> {
qprintln!("Authenticating {} ({:?}) using the web of trust:",
cert_fpr, signer_userid);
if let Ok(Some(cert_store)) = self.sq.cert_store() {
if let Some(cert_store) = self.sq.cert_store()? {
// Build the network.
let cert_store = sequoia_wot::store::CertStore::from_store(
cert_store, self.sq.policy, reference_time);
@ -432,6 +432,8 @@ impl<'c, 'store, 'rstore> VHelper<'c, 'store, 'rstore> {
qprintln!("");
}
Ok(())
}
}
@ -514,8 +516,9 @@ impl<'c, 'store, 'rstore> VerificationHelper for VHelper<'c, 'store, 'rstore>
qprintln!("Encrypted using {}", sym_algo);
}
},
MessageLayer::SignatureGroup { ref results } =>
self.print_sigs(results),
MessageLayer::SignatureGroup { ref results } => {
self.print_sigs(results)?;
},
}
}

View File

@ -456,18 +456,18 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
/// Returns the secret keys found in any specified keyrings.
pub fn keyring_tsks(&self)
-> &BTreeMap<Fingerprint,
(Fingerprint, Key<key::PublicParts, key::UnspecifiedRole>)>
-> Result<&BTreeMap<Fingerprint,
(Fingerprint, Key<key::PublicParts, key::UnspecifiedRole>)>>
{
if let Some(keyring_tsks) = self.keyring_tsks.get() {
keyring_tsks
Ok(keyring_tsks)
} else {
// This also initializes keyring_tsks.
let _ = self.cert_store();
self.cert_store()?;
// If something went wrong, we just set it to an empty
// map.
self.keyring_tsks.get_or_init(|| BTreeMap::new())
Ok(self.keyring_tsks.get_or_init(|| BTreeMap::new()))
}
}
@ -1293,7 +1293,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
let try_keyrings = |cert: &Cert, key: &Key<_, _>|
-> Result<_>
{
let keyring_tsks = self.keyring_tsks();
let keyring_tsks = self.keyring_tsks()?;
if let Some((cert_fpr, key))
= keyring_tsks.get(&key.fingerprint())
{
@ -1353,7 +1353,7 @@ impl<'store: 'rstore, 'rstore> Sq<'store, 'rstore> {
let try_keyrings = |cert: &Cert, key: &Key<_, _>|
-> Result<_>
{
let keyring_tsks = self.keyring_tsks();
let keyring_tsks = self.keyring_tsks()?;
if let Some((cert_fpr, key))
= keyring_tsks.get(&key.fingerprint())
{