diff options
-rw-r--r-- | openpgp/src/fingerprint.rs | 11 | ||||
-rw-r--r-- | openpgp/src/keyid.rs | 2 | ||||
-rw-r--r-- | openpgp/src/serialize.rs | 3 |
3 files changed, 15 insertions, 1 deletions
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs index 7ed623d1..5cc5907e 100644 --- a/openpgp/src/fingerprint.rs +++ b/openpgp/src/fingerprint.rs @@ -10,13 +10,20 @@ use quickcheck::{Arbitrary, Gen}; /// 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 Fingerprint { /// 20 byte SHA-1 hash. V4([u8;20]), /// Used for holding fingerprints that we don't understand. For /// instance, we don't grok v3 fingerprints. - 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 Fingerprint { @@ -72,6 +79,7 @@ impl Fingerprint { match self { &Fingerprint::V4(ref fp) => fp, &Fingerprint::Invalid(ref fp) => fp, + Fingerprint::__Nonexhaustive => unreachable!(), } } @@ -123,6 +131,7 @@ impl Fingerprint { let raw = match self { &Fingerprint::V4(ref fp) => &fp[..], &Fingerprint::Invalid(ref fp) => &fp[..], + Fingerprint::__Nonexhaustive => unreachable!(), }; // We currently only handle V4 fingerprints, which look like: diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs index 3729f285..1d0410df 100644 --- a/openpgp/src/keyid.rs +++ b/openpgp/src/keyid.rs @@ -108,6 +108,7 @@ impl From<&Fingerprint> for KeyID { Fingerprint::Invalid(fp) => { KeyID::Invalid(fp.clone()) } + Fingerprint::__Nonexhaustive => unreachable!(), } } } @@ -120,6 +121,7 @@ impl From<Fingerprint> for KeyID { Fingerprint::Invalid(fp) => { KeyID::Invalid(fp) } + Fingerprint::__Nonexhaustive => unreachable!(), } } } diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index a67da09d..9c0c79d9 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -837,6 +837,7 @@ impl MarshalInto for Fingerprint { match self { Fingerprint::V4(_) => 20, Fingerprint::Invalid(ref fp) => fp.len(), + Fingerprint::__Nonexhaustive => unreachable!(), } } @@ -1456,6 +1457,7 @@ impl MarshalInto for SubpacketValue { 1 + (fp as &dyn MarshalInto).serialized_len(), // Educated guess for unknown versions. Fingerprint::Invalid(_) => 1 + fp.as_bytes().len(), + Fingerprint::__Nonexhaustive => unreachable!(), }, PreferredAEADAlgorithms(ref p) => p.len(), IntendedRecipient(ref fp) => match fp { @@ -1463,6 +1465,7 @@ impl MarshalInto for SubpacketValue { 1 + (fp as &dyn MarshalInto).serialized_len(), // Educated guess for unknown versions. Fingerprint::Invalid(_) => 1 + fp.as_bytes().len(), + Fingerprint::__Nonexhaustive => unreachable!(), }, Unknown { body, .. } => body.len(), __Nonexhaustive => unreachable!(), |