summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyid.rs
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2020-03-18 14:54:26 +0100
committerWiktor Kwapisiewicz <wiktor@metacode.biz>2020-03-18 14:58:35 +0100
commite5b01bed4383e061cd79d3446c7710e53ad41d9a (patch)
tree68849cd74ad5753ba41f17e0103a0e1534d4ea63 /openpgp/src/keyid.rs
parent2b2a2abdb9c29c1d27daab06f51be4728ec9b308 (diff)
openpgp: Allow formatting KeyID with X and x
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r--openpgp/src/keyid.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index 1224a70c..44619252 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -20,6 +20,20 @@ impl fmt::Debug for KeyID {
}
}
+impl fmt::UpperHex for KeyID {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str(&self.convert_to_string(false))
+ }
+}
+
+impl fmt::LowerHex for KeyID {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut hex = self.convert_to_string(false);
+ hex.make_ascii_lowercase();
+ f.write_str(&hex)
+ }
+}
+
impl std::str::FromStr for KeyID {
type Err = anyhow::Error;
@@ -240,6 +254,13 @@ mod test {
}
#[test]
+ fn hex_formatting() {
+ let keyid = KeyID::from_hex("FB3751F1587DAEF1").unwrap();
+ assert_eq!(format!("{:X}", keyid), "FB3751F1587DAEF1");
+ assert_eq!(format!("{:x}", keyid), "fb3751f1587daef1");
+ }
+
+ #[test]
fn keyid_is_send_and_sync() {
fn f<T: Send + Sync>(_: T) {}
f(KeyID::from_hex("89AB CDEF 0123 4567").unwrap());