summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyid.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-09-29 17:16:14 +0200
committerJustus Winter <justus@sequoia-pgp.org>2023-09-29 17:16:14 +0200
commit20b7c634b216d3ce4ae136bc032bb117ece390b1 (patch)
tree88c20502dc77dff20914369f8f04703b47fa6770 /openpgp/src/keyid.rs
parent06b13acc10164f5bd651e4eb00facce4fa15beb2 (diff)
openpgp: Change the hex parsing to accept odd number of nibbles.
- This came up as the new leak tests use our hex parsing functions to parse /proc/self/maps and apparently Linux will drop leading zeros from addresses. - Fix this by allowing these functions to operate on an odd number of nibbles. I see no reason no reason not to do that, except for the fact that we don't want to establish that it is okay to drop leading zeros from key IDs and fingerprints, hence I preserved the behavior of parsing key IDs and fingerprints.
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r--openpgp/src/keyid.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index 1c83c63b..2d880706 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -97,6 +97,11 @@ impl std::str::FromStr for KeyID {
type Err = anyhow::Error;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+ if s.chars().filter(|c| ! c.is_whitespace()).count() % 2 == 1 {
+ return Err(Error::InvalidArgument(
+ "Odd number of nibbles".into()).into());
+ }
+
let bytes = crate::fmt::hex::decode_pretty(s)?;
// A KeyID is exactly 8 bytes long.