Enum sequoia_openpgp::KeyHandle [−][src]
pub enum KeyHandle {
Fingerprint(Fingerprint),
KeyID(KeyID),
}
Expand description
Enum representing an identifier for certificates and keys.
A KeyHandle
contains either a Fingerprint
or a KeyID
.
This is needed because signatures can reference their issuer
either by Fingerprint
or by KeyID
.
Currently, Sequoia supports version 4 fingerprints and Key ID only. Version 3 fingerprints and Key ID were deprecated by RFC 4880 in 2007.
A v4 fingerprint is, essentially, a 20-byte SHA-1 hash over the key’s public key packet. A v4 Key ID is defined as the fingerprint’s lower 8 bytes.
For the exact definition, see Section 12.2 of RFC 4880.
Both fingerprint and Key ID are used to identify a key, e.g., the issuer of a signature.
Examples
use openpgp::KeyHandle;
use openpgp::Packet;
use openpgp::parse::Parse;
let p = Packet::from_bytes(
"-----BEGIN PGP SIGNATURE-----
// ...
-----END PGP SIGNATURE-----")?;
if let Packet::Signature(sig) = p {
let issuers = sig.get_issuers();
assert_eq!(issuers.len(), 2);
assert_eq!(&issuers[0],
&KeyHandle::Fingerprint(
"C03F A641 1B03 AE12 5764 6118 7223 B566 78E0 2528"
.parse()?));
assert_eq!(&issuers[1],
&KeyHandle::KeyID("7223 B566 78E0 2528".parse()?));
} else {
unreachable!("It's a signature!");
}
Variants
Fingerprint(Fingerprint)
A Fingerprint.
Tuple Fields of Fingerprint
0: Fingerprint
KeyID(KeyID)
A KeyID.
Tuple Fields of KeyID
0: KeyID
Implementations
Returns the raw identifier as a byte slice.
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.
In these cases (and only these cases) KeyHandle
’s
PartialOrd
implementation returns None
to correctly
indicate that a comparison is not possible.
This definition of equality makes searching for a given
KeyHandle
using PartialEq
awkward. This function fills
that gap. It answers the question: given two KeyHandles
,
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!(! fpr1.eq(&fpr2));
assert!(fpr1.aliases(&keyid));
assert!(fpr2.aliases(&keyid));
assert!(! fpr1.aliases(&fpr2));
Returns whether the KeyHandle is invalid.
A KeyHandle is invalid if the Fingerprint
or KeyID
that it
contains is valid.
use sequoia_openpgp as openpgp;
use openpgp::Fingerprint;
use openpgp::KeyID;
use openpgp::KeyHandle;
// A perfectly valid fingerprint:
let kh : KeyHandle = "8F17 7771 18A3 3DDA 9BA4 8E62 AACB 3243 6300 52D9"
.parse()?;
assert!(! kh.is_invalid());
// But, V3 fingerprints are invalid.
let kh : KeyHandle = "9E 94 45 13 39 83 5F 70 7B E7 D8 ED C4 BE 5A A6"
.parse()?;
assert!(kh.is_invalid());
// A perfectly valid Key ID:
let kh : KeyHandle = "AACB 3243 6300 52D9"
.parse()?;
assert!(! kh.is_invalid());
// But, short Key IDs are invalid:
let kh : KeyHandle = "6300 52D9"
.parse()?;
assert!(kh.is_invalid());
Converts this KeyHandle
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::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());
Converts this KeyHandle
to its hexadecimal representation
with spaces.
This representation is always uppercase and with spaces grouping the hexadecimal digits into groups of four. It is only suitable for manual comparison of key handles.
Note: The spaces will hinder other kind of use cases. For example, it is harder to select the whole key handle for copying, and it has to be quoted when used as a command line argument. Only use this form for displaying a key handle with the intent of manual comparisons.
use openpgp::KeyHandle;
let h: KeyHandle =
"0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567".parse()?;
assert_eq!("0123 4567 89AB CDEF 0123 4567 89AB CDEF 0123 4567",
h.to_spaced_hex());
Trait Implementations
Performs the conversion.
Performs the conversion.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for KeyHandle
impl UnwindSafe for KeyHandle
Blanket Implementations
Mutably borrows from an owned value. Read more