diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-02-21 11:58:24 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-02-21 11:58:24 +0100 |
commit | f8c73c29c89557c4ec00f72576e8f4add62e66d7 (patch) | |
tree | 36910421c48ed3152006fbe66233bb79adbe850c | |
parent | a5ca70a2bc89ce7b5c20b1be3c66a04e905b3d47 (diff) |
openpgp: Mark enum Ciphertext as non-exhaustive.
-rw-r--r-- | openpgp/src/crypto/mpis.rs | 8 | ||||
-rw-r--r-- | openpgp/src/crypto/sexp.rs | 2 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 4 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 1 |
4 files changed, 15 insertions, 0 deletions
diff --git a/openpgp/src/crypto/mpis.rs b/openpgp/src/crypto/mpis.rs index 6f44c8c5..ff3cfb5b 100644 --- a/openpgp/src/crypto/mpis.rs +++ b/openpgp/src/crypto/mpis.rs @@ -822,6 +822,10 @@ pub enum Ciphertext { /// Any data that failed to parse. rest: Box<[u8]>, }, + + /// This marks this enum as non-exhaustive. Do not use this + /// variant. + #[doc(hidden)] __Nonexhaustive, } impl Ciphertext { @@ -847,6 +851,8 @@ impl Ciphertext { &Unknown { ref mpis, ref rest } => mpis.iter().map(|m| 2 + m.value.len()).sum::<usize>() + rest.len(), + + __Nonexhaustive => unreachable!(), } } @@ -863,6 +869,7 @@ impl Ciphertext { &ElGamal { .. } => Some(PublicKeyAlgorithm::ElGamalEncrypt), &ECDH { .. } => Some(PublicKeyAlgorithm::ECDH), &Unknown { .. } => None, + __Nonexhaustive => unreachable!(), } } } @@ -1150,6 +1157,7 @@ mod tests { ECDH, cur.into_inner()).unwrap(), Ciphertext::Unknown { .. } => unreachable!(), + Ciphertext::__Nonexhaustive => unreachable!(), }; ct == ct_ diff --git a/openpgp/src/crypto/sexp.rs b/openpgp/src/crypto/sexp.rs index 4939059e..86211dfb 100644 --- a/openpgp/src/crypto/sexp.rs +++ b/openpgp/src/crypto/sexp.rs @@ -81,6 +81,8 @@ impl Sexp { Err(Error::InvalidArgument( format!("Don't know how to convert {:?}", ciphertext)) .into()), + + __Nonexhaustive => unreachable!(), } } diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index 11b51b6c..9b477931 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -791,6 +791,8 @@ impl Serialize for crypto::mpis::Ciphertext { } w.write_all(rest)?; } + + __Nonexhaustive => unreachable!(), } Ok(()) @@ -817,6 +819,8 @@ impl SerializeInto for crypto::mpis::Ciphertext { mpis.iter().map(|mpi| mpi.serialized_len()).sum::<usize>() + rest.len() } + + __Nonexhaustive => unreachable!(), } } diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index d05263bf..26483865 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -609,6 +609,7 @@ impl PacketDumper { self.dump_mpis(output, &ii, &[rest], &["rest"])?; }, + mpis::Ciphertext::__Nonexhaustive => unreachable!(), } } }, |