summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-08-11 11:35:35 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-08-11 14:32:13 +0200
commitb914ce71ee71477fb6e9cefc916ece157943917d (patch)
treeee8126395a952d39cf7a20038265ceb8d4192902 /openpgp
parentc325bd5eee79cd83cc844e2dc7957aac4897ca61 (diff)
openpgp: Mark S2K as non-exhaustive to allow future extensions.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/crypto/s2k.rs10
-rw-r--r--openpgp/src/serialize.rs2
2 files changed, 12 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!(),
}
}