diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-01-02 11:48:16 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-01-02 13:32:02 +0100 |
commit | 75c1d18d7a7eb3e6889c651cfaf8e6c4da00b647 (patch) | |
tree | 8b713ea22c4e439d7ed462617392e63fc008cdb7 /openpgp/src | |
parent | 7a42b2e19ee506e688bece42c108eee4b4e06a54 (diff) |
openpgp: Mark enum Packet non-exhaustive.
- See #405.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/lib.rs | 9 | ||||
-rw-r--r-- | openpgp/src/packet/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 1 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 4 |
4 files changed, 16 insertions, 0 deletions
diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index f503f77f..a351c789 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -285,6 +285,9 @@ pub enum Error { /// than a `CompressedData` packet. /// /// [Section 5 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5 +/// +/// Note: This enum cannot be exhaustively matched to allow future +/// extensions. #[derive(Debug)] #[derive(PartialEq, Eq, Hash, Clone)] pub enum Packet { @@ -324,6 +327,10 @@ pub enum Packet { MDC(packet::MDC), /// AEAD Encrypted Data Packet. AED(packet::AED), + + /// This marks this enum as non-exhaustive. Do not use this + /// variant. + #[doc(hidden)] __Nonexhaustive, } impl Packet { @@ -353,6 +360,7 @@ impl Packet { &Packet::SEIP(_) => Tag::SEIP, &Packet::MDC(_) => Tag::MDC, &Packet::AED(_) => Tag::AED, + Packet::__Nonexhaustive => unreachable!(), } } @@ -384,6 +392,7 @@ impl Packet { &Packet::SEIP(_) => Some(Tag::SEIP), &Packet::MDC(_) => Some(Tag::MDC), &Packet::AED(_) => Some(Tag::AED), + Packet::__Nonexhaustive => unreachable!(), } } } diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs index 86f028de..b05d8a2b 100644 --- a/openpgp/src/packet/mod.rs +++ b/openpgp/src/packet/mod.rs @@ -74,6 +74,7 @@ impl<'a> Deref for Packet { &Packet::SEIP(ref packet) => &packet.common, &Packet::MDC(ref packet) => &packet.common, &Packet::AED(AED::V1(ref packet)) => &packet.common, + Packet::__Nonexhaustive => unreachable!(), } } } @@ -101,6 +102,7 @@ impl<'a> DerefMut for Packet { &mut Packet::SEIP(ref mut packet) => &mut packet.common, &mut Packet::MDC(ref mut packet) => &mut packet.common, &mut Packet::AED(AED::V1(ref mut packet)) => &mut packet.common, + Packet::__Nonexhaustive => unreachable!(), } } } diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 25ca01f8..d0123803 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -3566,6 +3566,7 @@ impl <'a> PacketParser<'a> { t!("A {:?} packet is not a container, not recursing.", self.packet.tag()); }, + Packet::__Nonexhaustive => unreachable!(), } // No recursion. diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index 70a8e67a..86df736c 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -2075,6 +2075,7 @@ impl Serialize for Packet { &Packet::SEIP(ref p) => p.serialize(o), &Packet::MDC(ref p) => p.serialize(o), &Packet::AED(ref p) => p.serialize(o), + Packet::__Nonexhaustive => unreachable!(), } } @@ -2116,6 +2117,7 @@ impl Serialize for Packet { &Packet::SEIP(ref p) => p.export(o), &Packet::MDC(ref p) => p.export(o), &Packet::AED(ref p) => p.export(o), + Packet::__Nonexhaustive => unreachable!(), } } } @@ -2141,6 +2143,7 @@ impl NetLength for Packet { &Packet::SEIP(ref p) => p.net_len(), &Packet::MDC(ref p) => p.net_len(), &Packet::AED(ref p) => p.net_len(), + Packet::__Nonexhaustive => unreachable!(), } } } @@ -2166,6 +2169,7 @@ impl SerializeInto for Packet { &Packet::SEIP(ref p) => p.serialized_len(), &Packet::MDC(ref p) => p.serialized_len(), &Packet::AED(ref p) => p.serialized_len(), + Packet::__Nonexhaustive => unreachable!(), }) + 1 // CTB. + BodyLength::Full(self.net_len() as u32).serialized_len() |