diff options
-rw-r--r-- | openpgp/src/crypto/s2k.rs | 10 | ||||
-rw-r--r-- | openpgp/src/serialize.rs | 2 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/openpgp/src/crypto/s2k.rs b/openpgp/src/crypto/s2k.rs index 10dd9440..0bc64af4 100644 --- a/openpgp/src/crypto/s2k.rs +++ b/openpgp/src/crypto/s2k.rs @@ -26,6 +26,9 @@ use rand::Rng; /// [Section 3.7 of RFC 4880]. /// /// [Section 3.7 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-3.7 +/// +/// Note: This enum cannot be exhaustively matched to allow future +/// extensions. #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub enum S2K { /// Simply hashes the password. @@ -55,6 +58,10 @@ pub enum S2K { Private(u8), /// Unknown S2K algorithm Unknown(u8), + + /// This marks this enum as non-exhaustive. Do not use this + /// variant. + #[doc(hidden)] __Nonexhaustive, } impl Default for S2K { @@ -141,6 +148,7 @@ impl S2K { } } &S2K::Unknown(_) | &S2K::Private(_) => unreachable!(), + S2K::__Nonexhaustive => unreachable!(), } hash.digest(data); @@ -152,6 +160,7 @@ impl S2K { &S2K::Unknown(u) | &S2K::Private(u) => Err(Error::MalformedPacket( format!("Unknown S2K type {:#x}", u)).into()), + S2K::__Nonexhaustive => unreachable!(), } } @@ -264,6 +273,7 @@ impl fmt::Display for S2K { S2K::Private(u) => f.write_fmt(format_args!("Private/Experimental S2K {}", u)), S2K::Unknown(u) => f.write_fmt(format_args!("Unknown S2K {}", u)), + S2K::__Nonexhaustive => unreachable!(), } } } diff --git a/openpgp/src/serialize.rs b/openpgp/src/serialize.rs index 8dc45808..502bbbcf 100644 --- a/openpgp/src/serialize.rs +++ b/openpgp/src/serialize.rs @@ -1257,6 +1257,7 @@ impl Marshal for S2K { &S2K::Private(s2k) | &S2K::Unknown(s2k) => { w.write_all(&[s2k])?; } + S2K::__Nonexhaustive => unreachable!(), } Ok(()) @@ -1271,6 +1272,7 @@ impl MarshalInto for S2K { &S2K::Salted{ .. } => 2 + 8, &S2K::Iterated{ .. } => 2 + 8 + 1, &S2K::Private(_) | &S2K::Unknown(_) => 1, + S2K::__Nonexhaustive => unreachable!(), } } diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index e99990ee..93986342 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -886,6 +886,7 @@ impl PacketDumper { writeln!(output, "Private({})", n)?, Unknown(n) => writeln!(output, "Unknown({})", n)?, + __Nonexhaustive => unreachable!(), } Ok(()) } |