summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openpgp/src/keyid.rs13
-rw-r--r--openpgp/src/serialize.rs2
2 files changed, 14 insertions, 1 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index f823299b..3729f285 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -14,6 +14,9 @@ use crate::Result;
/// generated, see [Section 12.2 of RFC 4880].
///
/// [Section 12.2 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-12.2
+///
+/// Note: This enum cannot be exhaustively matched to allow future
+/// extensions.
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Hash)]
pub enum KeyID {
/// Lower 8 byte SHA-1 hash.
@@ -21,7 +24,11 @@ pub enum KeyID {
/// Used for holding keyids that we don't understand. For
/// instance, we don't grok v3 keyids. And, it is possible that
/// the Issuer subpacket contains the wrong number of bytes.
- Invalid(Box<[u8]>)
+ Invalid(Box<[u8]>),
+
+ /// This marks this enum as non-exhaustive. Do not use this
+ /// variant.
+ #[doc(hidden)] __Nonexhaustive,
}
impl fmt::Display for KeyID {
@@ -75,6 +82,7 @@ impl From<KeyID> for Vec<u8> {
match id {
KeyID::V4(ref b) => r.extend_from_slice(b),
KeyID::Invalid(ref b) => r.extend_from_slice(b),
+ KeyID::__Nonexhaustive => unreachable!(),
}
r
}
@@ -130,6 +138,7 @@ impl KeyID {
Ok(u64::from_be_bytes(*b)),
KeyID::Invalid(_) =>
Err(Error::InvalidArgument("Invalid KeyID".into()).into()),
+ KeyID::__Nonexhaustive => unreachable!(),
}
}
@@ -149,6 +158,7 @@ impl KeyID {
match self {
&KeyID::V4(ref id) => id,
&KeyID::Invalid(ref id) => id,
+ KeyID::__Nonexhaustive => unreachable!(),
}
}
@@ -206,6 +216,7 @@ impl KeyID {
let raw = match self {
&KeyID::V4(ref fp) => &fp[..],
&KeyID::Invalid(ref fp) => &fp[..],
+ KeyID::__Nonexhaustive => unreachable!(),
};
// We currently only handle V4 key IDs, which look like:
diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs
index 476e77be..a67da09d 100644
--- a/openpgp/src/serialize.rs
+++ b/openpgp/src/serialize.rs
@@ -801,6 +801,7 @@ impl Marshal for KeyID {
let raw = match self {
&KeyID::V4(ref fp) => &fp[..],
&KeyID::Invalid(ref fp) => &fp[..],
+ KeyID::__Nonexhaustive => unreachable!(),
};
o.write_all(raw)?;
Ok(())
@@ -813,6 +814,7 @@ impl MarshalInto for KeyID {
match self {
&KeyID::V4(_) => 8,
&KeyID::Invalid(ref fp) => fp.len(),
+ KeyID::__Nonexhaustive => unreachable!(),
}
}