diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-12-22 13:07:29 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-12-22 13:07:29 +0100 |
commit | 70dd8e7f1dd643db7415c406ea264572528b8ee7 (patch) | |
tree | 848cd446f46d3269069a0087447668f19720f5b9 | |
parent | 455923648b254e9ea74bd05d1af46ab50a6a07eb (diff) |
openpgp: Implement KeyHandle::to_hex.
- We implement Fingerprint::to_hex and KeyID::to_hex. Also
implement it for KeyHandle.
-rw-r--r-- | openpgp/src/keyhandle.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/openpgp/src/keyhandle.rs b/openpgp/src/keyhandle.rs index 70e4dbda..2642caee 100644 --- a/openpgp/src/keyhandle.rs +++ b/openpgp/src/keyhandle.rs @@ -298,6 +298,32 @@ impl KeyHandle { self.partial_cmp(other.borrow()).unwrap_or(Ordering::Equal) == Ordering::Equal } + + /// Converts this fingerprint to its canonical hexadecimal + /// representation. + /// + /// This representation is always uppercase and without spaces and + /// is suitable for stable key identifiers. + /// + /// The output of this function is exactly the same as formatting + /// this object with the `:X` format specifier. + /// + /// ```rust + /// # fn main() -> sequoia_openpgp::Result<()> { + /// # use sequoia_openpgp as openpgp; + /// use openpgp::KeyHandle; + /// + /// let h: KeyHandle = + /// "0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?; + /// + /// assert_eq!("0123456789ABCDEF0123456789ABCDEF01234567", h.to_hex()); + /// assert_eq!(format!("{:X}", h), h.to_hex()); + /// # Ok(()) } + /// ``` + pub fn to_hex(&self) -> String { + format!("{:X}", self) + } + } #[cfg(test)] |