From 75b5b3fbbf8c33d10fd30e21f645b8ef1513363a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 21 Sep 2021 16:35:30 +0300 Subject: Improve error message for a malformed packet Suggested by Neal Walfield. Found by clippy lint useless_format: https://rust-lang.github.io/rust-clippy/master/index.html#useless_format --- openpgp/src/packet/pkesk.rs | 5 +++-- openpgp/src/parse.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'openpgp') diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index 40e7bc37..50ec187a 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -161,7 +161,8 @@ impl PKESK3 { if key_rgn.len() != sym_algo.key_size()? { return Err(Error::MalformedPacket( - format!("session key has the wrong size")).into()); + format!("session key has the wrong size (got: {}, expected: {})", + key_rgn.len(), sym_algo.key_size()?)).into()) } key.copy_from_slice(&plain[key_rgn]); @@ -174,7 +175,7 @@ impl PKESK3 { if their_checksum == our_checksum { Ok((sym_algo, key)) } else { - Err(Error::MalformedPacket(format!("key checksum wrong")) + Err(Error::MalformedPacket("key checksum wrong".to_string()) .into()) } } diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 549b94f2..eacded35 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -5185,11 +5185,11 @@ impl<'a> PacketParser<'a> { if self.content_was_read { return Err(Error::InvalidOperation( - format!("Packet's content has already been read.")).into()); + "Packet's content has already been read.".to_string()).into()); } if ! self.encrypted { return Err(Error::InvalidOperation( - format!("Packet not encrypted.")).into()); + "Packet not encrypted.".to_string()).into()); } if algo.key_size()? != key.len () { -- cgit v1.2.3