From 17fc6ebeffa044e45bf7242fe18633587350b83b Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Sun, 19 Jun 2022 14:32:48 +0200 Subject: [PATCH] Handle empty signing key slot in key_slot() --- openpgp-card-sequoia/src/util.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/openpgp-card-sequoia/src/util.rs b/openpgp-card-sequoia/src/util.rs index dcda297..1f268fc 100644 --- a/openpgp-card-sequoia/src/util.rs +++ b/openpgp-card-sequoia/src/util.rs @@ -245,17 +245,17 @@ pub fn key_slot(open: &mut Open, kt: KeyType) -> Result> { match kt { KeyType::Signing => { - // FIXME: handle empty signing key slot - - let pkm = open.public_key(KeyType::Signing)?; - - let key_sig = public_key_material_and_fp_to_key( - &pkm, - KeyType::Signing, - times.signature().expect("Signature time is unset"), - fps.signature().expect("Signature fingerprint is unset"), - )?; - Ok(Some(key_sig)) + if let Ok(pkm) = open.public_key(KeyType::Signing) { + if let Some(ts) = times.signature() { + return Ok(Some(public_key_material_and_fp_to_key( + &pkm, + KeyType::Signing, + ts, + fps.signature().expect("Signature fingerprint is unset"), + )?)); + } + } + Ok(None) } KeyType::Decryption => { if let Ok(pkm) = open.public_key(KeyType::Decryption) {