summaryrefslogtreecommitdiffstats
path: root/openpgp/src/keyid.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-03-02 11:25:58 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-03-02 11:46:20 +0100
commitcd94fae7726d565b89e4d7a14246046f9c23f29a (patch)
tree2bf5379af02363ce3ed7f111fa61dc1c50c2118d /openpgp/src/keyid.rs
parentf82d3e9a4d2e324405a1c115b3666d977567d377 (diff)
openpgp: Add methods for hexadecimal representation with spaces.
- These are explicitly intended for manual comparison of key ids and fingerprints. - See #422.
Diffstat (limited to 'openpgp/src/keyid.rs')
-rw-r--r--openpgp/src/keyid.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index cfa7ea6d..4e40b914 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -305,6 +305,31 @@ impl KeyID {
format!("{:X}", self)
}
+ /// Converts this `KeyID` to its hexadecimal representation with
+ /// spaces.
+ ///
+ /// This representation is always uppercase and with spaces
+ /// grouping the hexadecimal digits into groups of four. It is
+ /// suitable for manual comparison of Key IDs.
+ ///
+ /// Note: The spaces will hinder other kind of use cases. For
+ /// example, it is harder to select the whole Key ID for copying,
+ /// and it has to be quoted when used as a command line argument.
+ /// Only use this form for displaying a Key ID with the intent of
+ /// manual comparisons.
+ ///
+ /// ```rust
+ /// # fn main() -> sequoia_openpgp::Result<()> {
+ /// # use sequoia_openpgp as openpgp;
+ /// let keyid: openpgp::KeyID = "fb3751f1587daef1".parse()?;
+ ///
+ /// assert_eq!("FB37 51F1 587D AEF1", keyid.to_spaced_hex());
+ /// # Ok(()) }
+ /// ```
+ pub fn to_spaced_hex(&self) -> String {
+ self.convert_to_string(true)
+ }
+
/// Parses the hexadecimal representation of an OpenPGP `KeyID`.
///
/// This function is the reverse of `to_hex`. It also accepts