From 5cf8e9bb0c69e97311bb61840d4de9e8f5a23a61 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 19 Dec 2023 09:55:22 -0500 Subject: [PATCH] keyfork-shard: better error handling --- Cargo.lock | 9 +++++---- keyfork-shard/src/openpgp.rs | 4 ++-- keyfork-shard/src/openpgp/smartcard.rs | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82d8e43..57c4b80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -974,6 +974,7 @@ dependencies = [ "keyfork-mnemonic-util", "keyfork-plumbing", "keyfork-shard", + "serde", "smex", "thiserror", ] @@ -1956,18 +1957,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.190" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.190" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", diff --git a/keyfork-shard/src/openpgp.rs b/keyfork-shard/src/openpgp.rs index d3b1b5a..787a745 100644 --- a/keyfork-shard/src/openpgp.rs +++ b/keyfork-shard/src/openpgp.rs @@ -79,7 +79,7 @@ pub struct EncryptedMessage { } impl EncryptedMessage { - pub fn with_swap(pkesks: &mut Vec, seip: SEIP) -> Self { + pub fn new(pkesks: &mut Vec, seip: SEIP) -> Self { Self { pkesks: std::mem::take(pkesks), message: seip, @@ -156,7 +156,7 @@ pub fn parse_messages(reader: impl Read + Send + Sync) -> Result pkesks.push(p), Packet::SEIP(s) => { - encrypted_messages.push_back(EncryptedMessage::with_swap(&mut pkesks, s)); + encrypted_messages.push_back(EncryptedMessage::new(&mut pkesks, s)); } s => { panic!("Invalid variant found: {}", s.tag()); diff --git a/keyfork-shard/src/openpgp/smartcard.rs b/keyfork-shard/src/openpgp/smartcard.rs index 86cb54f..6807832 100644 --- a/keyfork-shard/src/openpgp/smartcard.rs +++ b/keyfork-shard/src/openpgp/smartcard.rs @@ -18,6 +18,9 @@ use openpgp_card_sequoia::{state::Open, types::Error as SequoiaCardError, Card}; #[derive(thiserror::Error, Debug)] pub enum Error { + #[error("Smart card could not decrypt any matching PKESK packets")] + SmartCardCouldNotDecrypt, + #[error("No smart card backend was stored")] SmartCardNotFound, @@ -264,6 +267,6 @@ impl DecryptionHelper for &mut SmartcardManager { } } - Err(Error::SmartCardNotFound.into()) + Err(Error::SmartCardCouldNotDecrypt.into()) } }