summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-06-29 12:40:46 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-06-29 12:53:18 +0200
commit39cc0042570d48c4acf221bf620628a5daf5f064 (patch)
tree15bafb13e22f65f127befd84c10b865e56cd0c4b
parente33289d32e5c520cbf8f8be6567101ae48348eea (diff)
openpgp: Implement Default and PartialEq for Keyflags.
-rw-r--r--openpgp/src/subpacket.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/openpgp/src/subpacket.rs b/openpgp/src/subpacket.rs
index 1a53f670..1caa2f68 100644
--- a/openpgp/src/subpacket.rs
+++ b/openpgp/src/subpacket.rs
@@ -1020,6 +1020,32 @@ quickcheck! {
/// information.
pub struct KeyFlags<'a>(Option<&'a [u8]>);
+impl<'a> Default for KeyFlags<'a> {
+ fn default() -> Self {
+ KeyFlags(None)
+ }
+}
+
+impl<'a> PartialEq for KeyFlags<'a> {
+ fn eq<'b>(&self, other: &'b KeyFlags) -> bool {
+ // To deal with unknown flags, we do a bitwise comparison.
+ // First, we need to bring both flag fields to the same
+ // length.
+ let len = ::std::cmp::max(self.0.map(|v| v.len()).unwrap_or(0),
+ other.0.map(|v| v.len()).unwrap_or(0));
+ let mut mine = vec![0; len];
+ let mut hers = vec![0; len];
+ if let Some(v) = self.0 {
+ &mut mine[..v.len()].copy_from_slice(&v);
+ }
+ if let Some(v) = other.0 {
+ &mut hers[..v.len()].copy_from_slice(&v);
+ }
+
+ mine == hers
+ }
+}
+
impl<'a> fmt::Debug for KeyFlags<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.can_certify() {