diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2020-09-22 00:45:53 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2020-11-06 09:46:53 +0100 |
commit | cdc9e16fb2aef0156d6af4abe3e519c22efa230e (patch) | |
tree | f4f5e10029ed7816bcb0931c53d27ed0e21c598c /openpgp/src/crypto | |
parent | 327a987e2c95ea9d05fcadd6fa7a8c249372affd (diff) |
openpgp: Use non_exhaustive attribute.
- Fixes #563
- With an MSRV >= 1.40.0, we can use #[non_exhaustive], as mentioned
in #406.
- This is also a clippy lint:
https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
Diffstat (limited to 'openpgp/src/crypto')
-rw-r--r-- | openpgp/src/crypto/backend/cng/ecdh.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/nettle/ecdh.rs | 2 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/nettle/hash.rs | 3 | ||||
-rw-r--r-- | openpgp/src/crypto/backend/nettle/symmetric.rs | 3 | ||||
-rw-r--r-- | openpgp/src/crypto/hash.rs | 1 | ||||
-rw-r--r-- | openpgp/src/crypto/mpi.rs | 31 | ||||
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 9 |
7 files changed, 6 insertions, 45 deletions
diff --git a/openpgp/src/crypto/backend/cng/ecdh.rs b/openpgp/src/crypto/backend/cng/ecdh.rs index a9118a87..b8f38577 100644 --- a/openpgp/src/crypto/backend/cng/ecdh.rs +++ b/openpgp/src/crypto/backend/cng/ecdh.rs @@ -142,8 +142,6 @@ where // N/A Curve::Unknown(_) | Curve::Ed25519 => Err(Error::UnsupportedEllipticCurve(curve.clone()).into()), - - Curve::__Nonexhaustive => unreachable!(), } } diff --git a/openpgp/src/crypto/backend/nettle/ecdh.rs b/openpgp/src/crypto/backend/nettle/ecdh.rs index 29e3d448..93d22a07 100644 --- a/openpgp/src/crypto/backend/nettle/ecdh.rs +++ b/openpgp/src/crypto/backend/nettle/ecdh.rs @@ -109,8 +109,6 @@ pub fn encrypt<R>(recipient: &Key<key::PublicParts, R>, // N/A Curve::Unknown(_) | Curve::Ed25519 => Err(Error::UnsupportedEllipticCurve(curve.clone()).into()), - - Curve::__Nonexhaustive => unreachable!(), } } else { Err(Error::InvalidArgument("Expected an ECDHPublicKey".into()).into()) diff --git a/openpgp/src/crypto/backend/nettle/hash.rs b/openpgp/src/crypto/backend/nettle/hash.rs index b4600b14..bf1d9cb5 100644 --- a/openpgp/src/crypto/backend/nettle/hash.rs +++ b/openpgp/src/crypto/backend/nettle/hash.rs @@ -29,7 +29,6 @@ impl HashAlgorithm { HashAlgorithm::MD5 => true, HashAlgorithm::Private(_) => false, HashAlgorithm::Unknown(_) => false, - HashAlgorithm::__Nonexhaustive => unreachable!(), } } @@ -60,7 +59,6 @@ impl HashAlgorithm { HashAlgorithm::RipeMD => Ok(Box::new(Ripemd160::default())), HashAlgorithm::Private(_) | HashAlgorithm::Unknown(_) => Err(Error::UnsupportedHashAlgorithm(self).into()), - HashAlgorithm::__Nonexhaustive => unreachable!(), } } @@ -78,7 +76,6 @@ impl HashAlgorithm { HashAlgorithm::RipeMD => Ok(rsa::ASN1_OID_RIPEMD160), HashAlgorithm::Private(_) | HashAlgorithm::Unknown(_) => Err(Error::UnsupportedHashAlgorithm(self).into()), - HashAlgorithm::__Nonexhaustive => unreachable!(), } } } diff --git a/openpgp/src/crypto/backend/nettle/symmetric.rs b/openpgp/src/crypto/backend/nettle/symmetric.rs index 4883a5a1..f25bcd7e 100644 --- a/openpgp/src/crypto/backend/nettle/symmetric.rs +++ b/openpgp/src/crypto/backend/nettle/symmetric.rs @@ -58,7 +58,6 @@ impl SymmetricAlgorithm { => true, Unencrypted | IDEA | Private(_) | Unknown(_) => false, - __Nonexhaustive => unreachable!(), } } @@ -246,4 +245,4 @@ impl SymmetricAlgorithm { _ => Err(Error::UnsupportedSymmetricAlgorithm(self).into()), } } -}
\ No newline at end of file +} diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs index 82add847..c7a8b248 100644 --- a/openpgp/src/crypto/hash.rs +++ b/openpgp/src/crypto/hash.rs @@ -305,7 +305,6 @@ impl Hash for Signature { fn hash(&self, hash: &mut Context) { match self { Signature::V4(sig) => sig.hash(hash), - Signature::__Nonexhaustive => unreachable!(), } } } diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs index 3918a4c2..8f9cfb2a 100644 --- a/openpgp/src/crypto/mpi.rs +++ b/openpgp/src/crypto/mpi.rs @@ -434,6 +434,7 @@ impl fmt::Debug for ProtectedMPI { /// /// Note: This enum cannot be exhaustively matched to allow future /// extensions. +#[non_exhaustive] #[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] pub enum PublicKey { /// RSA public key. @@ -501,10 +502,6 @@ pub enum PublicKey { /// 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 PublicKey { @@ -528,7 +525,6 @@ impl PublicKey { &ECDSA { ref curve,.. } => curve.bits(), &ECDH { ref curve,.. } => curve.bits(), &Unknown { .. } => None, - __Nonexhaustive => unreachable!(), } } @@ -544,7 +540,6 @@ impl PublicKey { ECDSA { .. } => Some(PublicKeyAlgorithm::ECDSA), ECDH { .. } => Some(PublicKeyAlgorithm::ECDH), Unknown { .. } => None, - __Nonexhaustive => unreachable!(), } } } @@ -614,6 +609,7 @@ impl Arbitrary for PublicKey { // Deriving Hash here is okay: PartialEq is manually implemented to // ensure that secrets are compared in constant-time. #[allow(clippy::derive_hash_xor_eq)] +#[non_exhaustive] #[derive(Clone, Hash)] pub enum SecretKeyMaterial { /// RSA secret key. @@ -665,10 +661,6 @@ pub enum SecretKeyMaterial { /// Any data that failed to parse. rest: Protected, }, - - /// This marks this enum as non-exhaustive. Do not use this - /// variant. - #[doc(hidden)] __Nonexhaustive, } impl fmt::Debug for SecretKeyMaterial { @@ -689,7 +681,6 @@ impl fmt::Debug for SecretKeyMaterial { write!(f, "ECDH {{ scalar: {:?} }}", scalar), &SecretKeyMaterial::Unknown{ ref mpis, ref rest } => write!(f, "Unknown {{ mips: {:?}, rest: {:?} }}", mpis, rest), - SecretKeyMaterial::__Nonexhaustive => unreachable!(), } } else { match self { @@ -707,7 +698,6 @@ impl fmt::Debug for SecretKeyMaterial { f.write_str("ECDH { <Redacted> }"), &SecretKeyMaterial::Unknown{ .. } => f.write_str("Unknown { <Redacted> }"), - SecretKeyMaterial::__Nonexhaustive => unreachable!(), } } } @@ -726,7 +716,6 @@ impl PartialOrd for SecretKeyMaterial { &SecretKeyMaterial::ECDSA{ .. } => 4, &SecretKeyMaterial::ECDH{ .. } => 5, &SecretKeyMaterial::Unknown{ .. } => 6, - SecretKeyMaterial::__Nonexhaustive => unreachable!(), } } @@ -812,7 +801,6 @@ impl SecretKeyMaterial { ECDSA { .. } => Some(PublicKeyAlgorithm::ECDSA), ECDH { .. } => Some(PublicKeyAlgorithm::ECDH), Unknown { .. } => None, - __Nonexhaustive => unreachable!(), } } } @@ -889,6 +877,7 @@ impl Default for SecretKeyChecksum { /// /// Note: This enum cannot be exhaustively matched to allow future /// extensions. +#[non_exhaustive] #[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] pub enum Ciphertext { /// RSA ciphertext. @@ -920,10 +909,6 @@ 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 { @@ -940,7 +925,6 @@ impl Ciphertext { &ElGamal { .. } => Some(PublicKeyAlgorithm::ElGamalEncrypt), &ECDH { .. } => Some(PublicKeyAlgorithm::ECDH), &Unknown { .. } => None, - __Nonexhaustive => unreachable!(), } } } @@ -986,6 +970,7 @@ impl Arbitrary for Ciphertext { /// /// Note: This enum cannot be exhaustively matched to allow future /// extensions. +#[non_exhaustive] #[derive(Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] pub enum Signature { /// RSA signature. @@ -1033,10 +1018,6 @@ pub enum Signature { /// 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 Hash for Signature { @@ -1111,7 +1092,6 @@ mod tests { PublicKey::parse(ECDH, cur).unwrap(), PublicKey::Unknown { .. } => unreachable!(), - PublicKey::__Nonexhaustive => unreachable!(), }; pk == pk_ @@ -1162,7 +1142,6 @@ mod tests { SecretKeyMaterial::parse(ElGamalEncrypt, cur).unwrap(), SecretKeyMaterial::Unknown { .. } => unreachable!(), - SecretKeyMaterial::__Nonexhaustive => unreachable!(), }; sk == sk_ @@ -1188,7 +1167,6 @@ mod tests { Ciphertext::parse(ECDH, cur).unwrap(), Ciphertext::Unknown { .. } => unreachable!(), - Ciphertext::__Nonexhaustive => unreachable!(), }; ct == ct_ @@ -1218,7 +1196,6 @@ mod tests { Signature::parse(ECDSA, cur).unwrap(), Signature::Unknown { .. } => unreachable!(), - Signature::__Nonexhaustive => unreachable!(), }; sig == sig_ diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 67198a0e..4eee84d8 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -33,6 +33,7 @@ use rand::Rng; /// /// Note: This enum cannot be exhaustively matched to allow future /// extensions. +#[non_exhaustive] #[derive(Clone, PartialEq, Eq, Hash, Debug)] pub enum S2K { /// Repeatently hashes the password with a public `salt` value. @@ -111,10 +112,6 @@ pub enum S2K { /// packet is serialized again, it is written out. parameters: Option<Box<[u8]>>, }, - - /// This marks this enum as non-exhaustive. Do not use this - /// variant. - #[doc(hidden)] __Nonexhaustive, } impl Default for S2K { @@ -229,7 +226,6 @@ impl S2K { } S2K::Unknown { .. } | &S2K::Private { .. } => unreachable!(), - S2K::__Nonexhaustive => unreachable!(), } hash.digest(data); @@ -241,7 +237,6 @@ impl S2K { S2K::Unknown { tag, .. } | S2K::Private { tag, .. } => Err(Error::MalformedPacket( format!("Unknown S2K type {:#x}", tag)).into()), - S2K::__Nonexhaustive => unreachable!(), } } @@ -251,7 +246,6 @@ impl S2K { #[allow(deprecated)] match self { Simple { .. } | Salted { .. } | Iterated { .. } => true, - __Nonexhaustive => unreachable!(), _ => false, } } @@ -367,7 +361,6 @@ impl fmt::Display for S2K { } else { write!(f, "Unknown S2K {}", tag) }, - S2K::__Nonexhaustive => unreachable!(), } } } |