summaryrefslogtreecommitdiffstats
path: root/openpgp/src/fingerprint.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/fingerprint.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/fingerprint.rs')
-rw-r--r--openpgp/src/fingerprint.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs
index 027e132c..00802093 100644
--- a/openpgp/src/fingerprint.rs
+++ b/openpgp/src/fingerprint.rs
@@ -171,6 +171,38 @@ impl Fingerprint {
format!("{:X}", self)
}
+ /// Converts this fingerprint to its hexadecimal representation
+ /// with spaces.
+ ///
+ /// This representation is always uppercase and with spaces
+ /// grouping the hexadecimal digits into groups of four with a
+ /// double space in the middle. It is only suitable for manual
+ /// comparison of fingerprints.
+ ///
+ /// Note: The spaces will hinder other kind of use cases. For
+ /// example, it is harder to select the whole fingerprint for
+ /// copying, and it has to be quoted when used as a command line
+ /// argument. Only use this form for displaying a fingerprint
+ /// with the intent of manual comparisons.
+ ///
+ /// See also [`Fingerprint::to_icao`].
+ ///
+ /// [`Fingerprint::to_icao`]: #method.to_icao
+ ///
+ /// ```rust
+ /// # fn main() -> sequoia_openpgp::Result<()> {
+ /// # use sequoia_openpgp as openpgp;
+ /// let fp: openpgp::Fingerprint =
+ /// "0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
+ ///
+ /// assert_eq!("0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567",
+ /// fp.to_spaced_hex());
+ /// # Ok(()) }
+ /// ```
+ pub fn to_spaced_hex(&self) -> String {
+ self.convert_to_string(true)
+ }
+
/// Parses the hexadecimal representation of an OpenPGP
/// fingerprint.
///