diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-03-02 12:54:32 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-03-02 12:54:32 +0100 |
commit | 6c2c6ca241ba499b699e70fa52b598d909a9e59e (patch) | |
tree | e99dd16231628f78edaad436e29d7a61aaeafaff | |
parent | ac859bff3b56a5823130c15fae6e0cbbc024c2d5 (diff) |
openpgp: Implement fmt::Display for NotationData.
- Fixes #667.
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index ac2b55f9..3885375c 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -1086,6 +1086,26 @@ pub struct NotationData { } assert_send_and_sync!(NotationData); +impl fmt::Display for NotationData { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.name)?; + + let flags = format!("{:?}", self.flags); + if ! flags.is_empty() { + write!(f, " ({})", flags)?; + } + + if self.flags.human_readable() { + write!(f, ": {}", String::from_utf8_lossy(&self.value))?; + } else { + let hex = crate::fmt::hex::encode(&self.value); + write!(f, ": {}", hex)?; + } + + Ok(()) + } +} + impl fmt::Debug for NotationData { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut dbg = f.debug_struct("NotationData"); |