From 71b9cdce50061de4a5af491f544a54ca95173b24 Mon Sep 17 00:00:00 2001 From: Caporal Winnie Date: Tue, 21 Apr 2026 23:05:06 +0200 Subject: [PATCH 1/3] added gpg export certification lookup as fallback --- crates/gpg/src/keybox.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/gpg/src/keybox.rs b/crates/gpg/src/keybox.rs index 05a3ee0..32308c7 100644 --- a/crates/gpg/src/keybox.rs +++ b/crates/gpg/src/keybox.rs @@ -5,6 +5,7 @@ use sequoia_openpgp::cert::prelude::*; use sequoia_openpgp::parse::Parse; use std::ffi::OsStr; use std::path::{Path, PathBuf}; +use std::process::Command; fn gnupg_home() -> Result { if let Ok(dir) = std::env::var("GNUPGHOME") { @@ -151,6 +152,22 @@ pub fn load_cert(spec: &str) -> Result { let matches = find_certs_in_keybox(&certs, spec); if matches.is_empty() { + tracing::debug!(spec = spec, "No matching cert in keybox, trying `gpg --export` fallback"); + + match Command::new("gpg").args(&["--export", "-a", spec]).output() { + Ok(out) if !out.stdout.is_empty() => { + tracing::debug!(size = out.stdout.len(), "gpg export returned data"); + return Cert::from_bytes(&out.stdout) + .with_context(|| format!("Failed to parse certificate exported by gpg for '{}'", spec)); + } + Ok(_) => { + tracing::debug!(spec = spec, "`gpg --export` had no output we fall through to the original error."); + } + Err(e) => { + tracing::debug!(error = %e, "Failed to run `gpg --export` fallback"); + } + } + bail!( "No matching certificate found for '{}'. Provide a .asc file path or import the key into your keybox.", spec From 871a8dbcc13208677492041cd368574d413e384f Mon Sep 17 00:00:00 2001 From: Caporal Winnie Date: Wed, 22 Apr 2026 18:40:23 +0200 Subject: [PATCH 2/3] Apply suggestion from @coderabbitai[bot] Seems like a reasonable change Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- crates/gpg/src/keybox.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/gpg/src/keybox.rs b/crates/gpg/src/keybox.rs index 32308c7..192decd 100644 --- a/crates/gpg/src/keybox.rs +++ b/crates/gpg/src/keybox.rs @@ -155,11 +155,18 @@ pub fn load_cert(spec: &str) -> Result { tracing::debug!(spec = spec, "No matching cert in keybox, trying `gpg --export` fallback"); match Command::new("gpg").args(&["--export", "-a", spec]).output() { - Ok(out) if !out.stdout.is_empty() => { + Ok(out) if out.status.success() && !out.stdout.is_empty() => { tracing::debug!(size = out.stdout.len(), "gpg export returned data"); return Cert::from_bytes(&out.stdout) .with_context(|| format!("Failed to parse certificate exported by gpg for '{}'", spec)); } + Ok(out) if !out.status.success() => { + tracing::debug!( + status = ?out.status.code(), + stderr = %String::from_utf8_lossy(&out.stderr), + "`gpg --export` failed" + ); + } Ok(_) => { tracing::debug!(spec = spec, "`gpg --export` had no output we fall through to the original error."); } From 33cf7a4e4fe3ab3a3ea03307b424f419068d57d2 Mon Sep 17 00:00:00 2001 From: Caporal Winnie Date: Wed, 22 Apr 2026 18:43:06 +0200 Subject: [PATCH 3/3] ran rustfmt --- crates/gpg/src/keybox.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/gpg/src/keybox.rs b/crates/gpg/src/keybox.rs index 192decd..74c8b30 100644 --- a/crates/gpg/src/keybox.rs +++ b/crates/gpg/src/keybox.rs @@ -152,7 +152,10 @@ pub fn load_cert(spec: &str) -> Result { let matches = find_certs_in_keybox(&certs, spec); if matches.is_empty() { - tracing::debug!(spec = spec, "No matching cert in keybox, trying `gpg --export` fallback"); + tracing::debug!( + spec = spec, + "No matching cert in keybox, trying `gpg --export` fallback" + ); match Command::new("gpg").args(&["--export", "-a", spec]).output() { Ok(out) if out.status.success() && !out.stdout.is_empty() => { @@ -168,7 +171,10 @@ pub fn load_cert(spec: &str) -> Result { ); } Ok(_) => { - tracing::debug!(spec = spec, "`gpg --export` had no output we fall through to the original error."); + tracing::debug!( + spec = spec, + "`gpg --export` had no output we fall through to the original error." + ); } Err(e) => { tracing::debug!(error = %e, "Failed to run `gpg --export` fallback");