diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-02-20 11:58:46 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-02-20 11:58:46 +0100 |
commit | 2d92addba5e985994cebd8a41b8e921ba6137bc9 (patch) | |
tree | 1d5b396bb9c8dbcde1af9e642dabe1845234a49e /openpgp/src/types/server_preferences.rs | |
parent | caa8e0df9bdfe13c8c43062fdc05cf2fa7ebbf2d (diff) |
openpgp: Improve debug formatting of the bitfield types.
- Do not erroneously report padding for KeyFlags.
- Print unknown flags and padding for KeyServerPreferences.
- Provide nicer output for Features.
Diffstat (limited to 'openpgp/src/types/server_preferences.rs')
-rw-r--r-- | openpgp/src/types/server_preferences.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/openpgp/src/types/server_preferences.rs b/openpgp/src/types/server_preferences.rs index 549ae07e..42c0a74d 100644 --- a/openpgp/src/types/server_preferences.rs +++ b/openpgp/src/types/server_preferences.rs @@ -18,8 +18,23 @@ impl Default for KeyServerPreferences { impl fmt::Debug for KeyServerPreferences { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut dirty = false; if self.no_modify() { f.write_str("no modify")?; + dirty = true; + } + if ! self.unknown.is_empty() { + if dirty { f.write_str(", ")?; } + f.write_str("+0x")?; + f.write_str( + &crate::fmt::hex::encode_pretty(&self.unknown))?; + dirty = true; + } + if self.pad_to > + KEYSERVER_PREFERENCES_N_KNOWN_BYTES + self.unknown.len() + { + if dirty { f.write_str(", ")?; } + write!(f, "+padding({} bytes)", self.pad_to - self.unknown.len())?; } Ok(()) @@ -105,6 +120,9 @@ impl KeyServerPreferences { /// than one person. const KEYSERVER_PREFERENCE_NO_MODIFY: u8 = 0x80; +/// Number of bytes with known flags. +const KEYSERVER_PREFERENCES_N_KNOWN_BYTES: usize = 1; + #[cfg(test)] mod tests { use super::*; |