summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-03-02 11:39:33 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-03-02 12:54:04 +0100
commitac859bff3b56a5823130c15fae6e0cbbc024c2d5 (patch)
tree65ec35f3aec64267811c42147ca021c69ac618bf
parent0201c6e6e5bb0ee6b1aed26e92d769675db63d96 (diff)
openpgp: Implement nicer fmt::Debug for NotationData.
- See #667.
-rw-r--r--openpgp/src/packet/signature/subpacket.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 10ad1277..ac2b55f9 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -1078,7 +1078,7 @@ impl SubpacketArea {
/// 5.2.3.16 of RFC 4880] for details.
///
/// [Section 5.2.3.16 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.16
-#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NotationData {
flags: NotationDataFlags,
name: String,
@@ -1086,6 +1086,36 @@ pub struct NotationData {
}
assert_send_and_sync!(NotationData);
+impl fmt::Debug for NotationData {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut dbg = f.debug_struct("NotationData");
+ dbg.field("name", &self.name);
+
+ let flags = format!("{:?}", self.flags);
+ if ! flags.is_empty() {
+ dbg.field("flags", &flags);
+ }
+
+ if self.flags.human_readable() {
+ match std::str::from_utf8(&self.value) {
+ Ok(s) => {
+ dbg.field("value", &s);
+ },
+ Err(e) => {
+ let s = format!("({}): {}", e,
+ crate::fmt::hex::encode(&self.value));
+ dbg.field("value", &s);
+ },
+ }
+ } else {
+ let hex = crate::fmt::hex::encode(&self.value);
+ dbg.field("value", &hex);
+ }
+
+ dbg.finish()
+ }
+}
+
#[cfg(test)]
impl Arbitrary for NotationData {
fn arbitrary<G: Gen>(g: &mut G) -> Self {