diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-06-11 11:17:52 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-06-11 11:18:10 +0200 |
commit | 6055a98b431321a9dd2f74eb8bca7c0f0907ce4a (patch) | |
tree | 5fd8b8427167cd858639d260cf279dc929686642 /openpgp/src/keyid.rs | |
parent | a86c0f3c0e312a4d82e8cc211ba89676c0a2db02 (diff) |
openpgp: Mark enum KeyID as non-exhaustive.
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r-- | openpgp/src/keyid.rs | 13 |
1 files changed, 12 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: |