Enum Fingerprint
#[non_exhaustive]pub enum Fingerprint {
V6([u8; 32]),
V4([u8; 20]),
Unknown {
version: Option<u8>,
bytes: Box<[u8]>,
},
}Expand description
A key’s fingerprint, as the crates that do not use Sequoia themselves name it. A long identifier for certificates and keys.
A Fingerprint uniquely identifies a public key.
Currently, Sequoia supports version 6 fingerprints and Key IDs, and version 4 fingerprints and Key IDs. Version 3 fingerprints and Key IDs were deprecated by RFC 4880 in 2007.
Essentially, a fingerprint is a hash over the key’s public key packet. For details, see Section 5.5.4 of RFC 9580.
Fingerprints are used, for example, to reference the issuing key
of a signature in its IssuerFingerprint subpacket. As a
general rule of thumb, you should prefer using fingerprints over
KeyIDs because the latter are vulnerable to birthday attacks.
§Examples
use openpgp::Fingerprint;
let fp: Fingerprint =
"0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
assert_eq!("0123456789ABCDEF0123456789ABCDEF01234567", fp.to_hex());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
V6([u8; 32])
Fingerprint of v6 certificates and keys.
V4([u8; 20])
Fingerprint of v4 certificates and keys.
Unknown
Fingerprint of unknown version or shape.
Implementations§
§impl Fingerprint
impl Fingerprint
pub fn from_bytes(version: u8, raw: &[u8]) -> Result<Fingerprint, Error>
pub fn from_bytes(version: u8, raw: &[u8]) -> Result<Fingerprint, Error>
Creates a Fingerprint from a byte slice in big endian
representation.
§Examples
use openpgp::Fingerprint;
let fp: Fingerprint =
"0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
let bytes =
[0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23,
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67];
assert_eq!(Fingerprint::from_bytes(4, &bytes)?, fp);pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the raw fingerprint as a byte slice in big endian representation.
§Examples
use openpgp::Fingerprint;
let fp: Fingerprint =
"0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
assert_eq!(fp.as_bytes(),
[0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23,
0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67]);pub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
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.
use openpgp::Fingerprint;
let fp: Fingerprint =
"0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
assert_eq!("0123456789ABCDEF0123456789ABCDEF01234567", fp.to_hex());
assert_eq!(format!("{:X}", fp), fp.to_hex());pub fn to_spaced_hex(&self) -> String
pub fn to_spaced_hex(&self) -> String
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.
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());pub fn from_hex(s: &str) -> Result<Fingerprint, Error>
pub fn from_hex(s: &str) -> Result<Fingerprint, Error>
Parses the hexadecimal representation of an OpenPGP fingerprint.
This function is the reverse of to_hex. It also accepts
other variants of the fingerprint notation including
lower-case letters, spaces and optional leading 0x.
use openpgp::Fingerprint;
let fp =
Fingerprint::from_hex("0123456789ABCDEF0123456789ABCDEF01234567")?;
assert_eq!("0123456789ABCDEF0123456789ABCDEF01234567", fp.to_hex());
let fp =
Fingerprint::from_hex("0123 4567 89ab cdef 0123 4567 89ab cdef 0123 4567")?;
assert_eq!("0123456789ABCDEF0123456789ABCDEF01234567", fp.to_hex());pub fn to_icao(&self) -> String
pub fn to_icao(&self) -> String
Converts the hex representation of the Fingerprint to a
phrase in the ICAO spelling alphabet.
§Examples
use openpgp::Fingerprint;
let fp: Fingerprint =
"01AB 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
assert!(fp.to_icao().starts_with("Zero One Alfa Bravo"));
pub fn aliases<H>(&self, other: H) -> boolwhere
H: Borrow<KeyHandle>,
pub fn aliases<H>(&self, other: H) -> boolwhere
H: Borrow<KeyHandle>,
Returns whether self and other could be aliases of each
other.
KeyHandle’s PartialEq implementation cannot assert that a
Fingerprint and a KeyID are equal, because distinct
fingerprints may have the same KeyID, and PartialEq must
be transitive, i.e.,
a == b and b == c implies a == c.That is, if fpr1 and fpr2 are distinct fingerprints with the
same key ID then:
fpr1 == keyid and fpr2 == keyid, but fpr1 != fpr2.This definition of equality makes searching for a given
KeyHandle using PartialEq awkward. This function fills
that gap. It answers the question: given a KeyHandle and a
Fingerprint, could they be aliases? That is, it implements
the desired, non-transitive equality relation:
// fpr1 and fpr2 are different fingerprints with the same KeyID.
assert_ne!(fpr1, fpr2);
assert!(fpr1.aliases(KeyHandle::from(&keyid)));
assert!(fpr2.aliases(KeyHandle::from(&keyid)));
assert!(! fpr1.aliases(KeyHandle::from(&fpr2)));Trait Implementations§
§impl Clone for Fingerprint
impl Clone for Fingerprint
§fn clone(&self) -> Fingerprint
fn clone(&self) -> Fingerprint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for Fingerprint
impl Debug for Fingerprint
§impl Display for Fingerprint
impl Display for Fingerprint
impl Eq for Fingerprint
§impl FromStr for Fingerprint
impl FromStr for Fingerprint
§impl Hash for Fingerprint
impl Hash for Fingerprint
§impl LowerHex for Fingerprint
impl LowerHex for Fingerprint
§impl Marshal for Fingerprint
impl Marshal for Fingerprint
§impl MarshalInto for Fingerprint
impl MarshalInto for Fingerprint
§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
§fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Error>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Error>
§impl Ord for Fingerprint
impl Ord for Fingerprint
§fn cmp(&self, other: &Fingerprint) -> Ordering
fn cmp(&self, other: &Fingerprint) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialEq for Fingerprint
impl PartialEq for Fingerprint
§impl PartialOrd for Fingerprint
impl PartialOrd for Fingerprint
§impl Serialize for Fingerprint
impl Serialize for Fingerprint
§impl SerializeInto for Fingerprint
impl SerializeInto for Fingerprint
§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
§fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Error>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize, Error>
impl StructuralPartialEq for Fingerprint
§impl TryFrom<&KeyHandle> for Fingerprint
impl TryFrom<&KeyHandle> for Fingerprint
§impl TryFrom<KeyHandle> for Fingerprint
impl TryFrom<KeyHandle> for Fingerprint
Auto Trait Implementations§
impl Freeze for Fingerprint
impl RefUnwindSafe for Fingerprint
impl Send for Fingerprint
impl Sync for Fingerprint
impl Unpin for Fingerprint
impl UnsafeUnpin for Fingerprint
impl UnwindSafe for Fingerprint
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Conv for T
impl<T> Conv for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.