keyfork-shard: better error handling

This commit is contained in:
Ryan Heywood 2023-12-19 09:55:22 -05:00
parent f91ca2f709
commit 5cf8e9bb0c
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
3 changed files with 11 additions and 7 deletions

9
Cargo.lock generated
View File

@ -974,6 +974,7 @@ dependencies = [
"keyfork-mnemonic-util", "keyfork-mnemonic-util",
"keyfork-plumbing", "keyfork-plumbing",
"keyfork-shard", "keyfork-shard",
"serde",
"smex", "smex",
"thiserror", "thiserror",
] ]
@ -1956,18 +1957,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.190" version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.190" version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@ -79,7 +79,7 @@ pub struct EncryptedMessage {
} }
impl EncryptedMessage { impl EncryptedMessage {
pub fn with_swap(pkesks: &mut Vec<PKESK>, seip: SEIP) -> Self { pub fn new(pkesks: &mut Vec<PKESK>, seip: SEIP) -> Self {
Self { Self {
pkesks: std::mem::take(pkesks), pkesks: std::mem::take(pkesks),
message: seip, message: seip,
@ -156,7 +156,7 @@ pub fn parse_messages(reader: impl Read + Send + Sync) -> Result<VecDeque<Encryp
match packet { match packet {
Packet::PKESK(p) => pkesks.push(p), Packet::PKESK(p) => pkesks.push(p),
Packet::SEIP(s) => { Packet::SEIP(s) => {
encrypted_messages.push_back(EncryptedMessage::with_swap(&mut pkesks, s)); encrypted_messages.push_back(EncryptedMessage::new(&mut pkesks, s));
} }
s => { s => {
panic!("Invalid variant found: {}", s.tag()); panic!("Invalid variant found: {}", s.tag());

View File

@ -18,6 +18,9 @@ use openpgp_card_sequoia::{state::Open, types::Error as SequoiaCardError, Card};
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum Error { pub enum Error {
#[error("Smart card could not decrypt any matching PKESK packets")]
SmartCardCouldNotDecrypt,
#[error("No smart card backend was stored")] #[error("No smart card backend was stored")]
SmartCardNotFound, SmartCardNotFound,
@ -264,6 +267,6 @@ impl DecryptionHelper for &mut SmartcardManager {
} }
} }
Err(Error::SmartCardNotFound.into()) Err(Error::SmartCardCouldNotDecrypt.into())
} }
} }