pub struct Signature { /* private fields */ }Expand description
Signature Packet
Ref https://www.rfc-editor.org/rfc/rfc9580.html#name-signature-packet-type-id-2
OpenPGP Signatures are a very generic mechanism. They are always used by a signer to make a
statement about some data payload, and the SignatureConfig metadata of the signature packet.
The statement can be verified by anyone with access to the signer’s public key, the payload
data, and the signature packet.
Signature packets are used in two very distinct contexts:
- As data signatures (either inline, in OpenPGP Messages, or as detached signatures over standalone data files).
- As certificate-forming signatures (e.g. to bind a subkey to a primary key).
For data signatures, the signer’s intended statement is usually either “I am the author of this payload” (e.g. for an email), or “I confirm that this payload has been handled appropriately” (e.g. to signal that a software package has been built by the infrastructure of a Linux distribution).
For certificate-forming signatures, typical statements of signature packets are “the primary key holder wants to associate this subkey with the primary”, or “the key holder wants to associate this identity (e.g. an email address) with their primary key”. Third-party signatures can be used by third parties to make statements, e.g. that they have verified that an identity is validly associated with a key (such as: “I have verified that this key belongs to Alice”).
The purpose of a signature packet is marked by its SignatureType.
Implementations§
Source§impl Signature
impl Signature
Sourcepub fn try_from_reader<B: BufRead>(
packet_header: PacketHeader,
i: B,
) -> Result<Self>
pub fn try_from_reader<B: BufRead>( packet_header: PacketHeader, i: B, ) -> Result<Self>
Parses a Signature packet from the given buffer
Ref: https://www.rfc-editor.org/rfc/rfc9580.html#name-signature-packet-type-id-2
Source§impl Signature
impl Signature
Sourcepub fn v2(
packet_header: PacketHeader,
typ: SignatureType,
pub_alg: PublicKeyAlgorithm,
hash_alg: HashAlgorithm,
created: Timestamp,
issuer_key_id: KeyId,
signed_hash_value: [u8; 2],
signature: SignatureBytes,
) -> Self
pub fn v2( packet_header: PacketHeader, typ: SignatureType, pub_alg: PublicKeyAlgorithm, hash_alg: HashAlgorithm, created: Timestamp, issuer_key_id: KeyId, signed_hash_value: [u8; 2], signature: SignatureBytes, ) -> Self
Constructor for an OpenPGP v2 signature packet. Note: This is a historical packet version!
Sourcepub fn v3(
packet_header: PacketHeader,
typ: SignatureType,
pub_alg: PublicKeyAlgorithm,
hash_alg: HashAlgorithm,
created: Timestamp,
issuer_key_id: KeyId,
signed_hash_value: [u8; 2],
signature: SignatureBytes,
) -> Self
pub fn v3( packet_header: PacketHeader, typ: SignatureType, pub_alg: PublicKeyAlgorithm, hash_alg: HashAlgorithm, created: Timestamp, issuer_key_id: KeyId, signed_hash_value: [u8; 2], signature: SignatureBytes, ) -> Self
Constructor for an OpenPGP v3 signature packet. Note: This is a historical packet version!
Sourcepub fn v4(
packet_header: PacketHeader,
typ: SignatureType,
pub_alg: PublicKeyAlgorithm,
hash_alg: HashAlgorithm,
signed_hash_value: [u8; 2],
signature: SignatureBytes,
hashed_subpackets: Vec<Subpacket>,
unhashed_subpackets: Vec<Subpacket>,
) -> Self
pub fn v4( packet_header: PacketHeader, typ: SignatureType, pub_alg: PublicKeyAlgorithm, hash_alg: HashAlgorithm, signed_hash_value: [u8; 2], signature: SignatureBytes, hashed_subpackets: Vec<Subpacket>, unhashed_subpackets: Vec<Subpacket>, ) -> Self
Constructor for an OpenPGP v4 signature packet.
OpenPGP v4 signatures are typically used with OpenPGP v4 keys, as specified in RFC 9580 (and formerly in 4880 and 2440).
Sourcepub fn v6(
packet_header: PacketHeader,
typ: SignatureType,
pub_alg: PublicKeyAlgorithm,
hash_alg: HashAlgorithm,
signed_hash_value: [u8; 2],
signature: SignatureBytes,
hashed_subpackets: Vec<Subpacket>,
unhashed_subpackets: Vec<Subpacket>,
salt: Vec<u8>,
) -> Self
pub fn v6( packet_header: PacketHeader, typ: SignatureType, pub_alg: PublicKeyAlgorithm, hash_alg: HashAlgorithm, signed_hash_value: [u8; 2], signature: SignatureBytes, hashed_subpackets: Vec<Subpacket>, unhashed_subpackets: Vec<Subpacket>, salt: Vec<u8>, ) -> Self
Constructor for an OpenPGP v6 signature packet.
OpenPGP v6 signatures are specified in RFC 9580 and only used with OpenPGP v6 keys.
Sourcepub fn unknown(
packet_header: PacketHeader,
version: SignatureVersion,
data: Bytes,
) -> Self
pub fn unknown( packet_header: PacketHeader, version: SignatureVersion, data: Bytes, ) -> Self
Create a signature of unknown version
pub fn from_config( config: SignatureConfig, signed_hash_value: [u8; 2], signature: SignatureBytes, ) -> Result<Self>
Sourcepub fn config(&self) -> Option<&SignatureConfig>
pub fn config(&self) -> Option<&SignatureConfig>
Returns the SignatureConfig if this is a known signature format.
Sourcepub fn unhashed_subpacket_push(&mut self, subpacket: Subpacket) -> Result<()>
pub fn unhashed_subpacket_push(&mut self, subpacket: Subpacket) -> Result<()>
Appends a subpacket at the back of the unhashed area
Sourcepub fn unhashed_subpacket_insert(
&mut self,
index: usize,
subpacket: Subpacket,
) -> Result<()>
pub fn unhashed_subpacket_insert( &mut self, index: usize, subpacket: Subpacket, ) -> Result<()>
Insert a subpacket into the unhashed area at position index, shifting all subpackets
after it to the right
Sourcepub fn unhashed_subpacket_remove(&mut self, index: usize) -> Result<Subpacket>
pub fn unhashed_subpacket_remove(&mut self, index: usize) -> Result<Subpacket>
Removes and returns the unhashed subpacket at position index, shifting all other
unhashed subpackets to the left
Sourcepub fn unhashed_subpackets_sort_by<F>(&mut self, compare: F)
pub fn unhashed_subpackets_sort_by<F>(&mut self, compare: F)
Sorts the subpackets in the unhashed area with a comparison function, preserving initial order of equal elements.
Sourcepub fn version(&self) -> SignatureVersion
pub fn version(&self) -> SignatureVersion
Returns the SignatureVersion.
Sourcepub fn typ(&self) -> Option<SignatureType>
pub fn typ(&self) -> Option<SignatureType>
Returns what kind of signature this is.
Sourcepub fn hash_alg(&self) -> Option<HashAlgorithm>
pub fn hash_alg(&self) -> Option<HashAlgorithm>
The used HashAlgorithm.
Sourcepub fn signature(&self) -> Option<&SignatureBytes>
pub fn signature(&self) -> Option<&SignatureBytes>
Returns the actual byte level signature.
pub fn signed_hash_value(&self) -> Option<[u8; 2]>
Sourcepub fn verify<R>(&self, key: &impl VerifyingKey, data: R) -> Result<()>where
R: Read,
pub fn verify<R>(&self, key: &impl VerifyingKey, data: R) -> Result<()>where
R: Read,
Verify this signature.
Sourcepub fn verify_certification<V>(
&self,
key: &V,
tag: Tag,
id: &impl Serialize,
) -> Result<()>where
V: VerifyingKey + Serialize,
pub fn verify_certification<V>(
&self,
key: &V,
tag: Tag,
id: &impl Serialize,
) -> Result<()>where
V: VerifyingKey + Serialize,
Verifies a certification signature or certification revocation signature (for self-signatures).
Allowed signature types are:
- Generic Certification Signature (Type ID 0x10)
- Persona Certification Signature (Type ID 0x11)
- Casual Certification Signature (Type ID 0x12)
- Positive Certification Signature (Type ID 0x13)
- Certification Revocation Signature (Type ID 0x30)
Sourcepub fn verify_third_party_certification<V, K>(
&self,
signee: &K,
signer: &V,
tag: Tag,
id: &impl Serialize,
) -> Result<()>
pub fn verify_third_party_certification<V, K>( &self, signee: &K, signer: &V, tag: Tag, id: &impl Serialize, ) -> Result<()>
Verifies a (possibly third-party) certification signature or certification revocation signature.
Allowed signature types are:
- Generic Certification Signature (Type ID 0x10)
- Persona Certification Signature (Type ID 0x11)
- Casual Certification Signature (Type ID 0x12)
- Positive Certification Signature (Type ID 0x13)
- Certification Revocation Signature (Type ID 0x30)
Sourcepub fn verify_subkey_binding<V, K>(&self, signer: &V, signee: &K) -> Result<()>
pub fn verify_subkey_binding<V, K>(&self, signer: &V, signee: &K) -> Result<()>
Verifies a subkey binding (which binds a subkey to the primary key) or subkey revocation signature.
The primary key is expected as signer, the subkey as signee.
Allowed signature types are:
- Subkey Binding Signature (type ID 0x18)
- Subkey Revocation Signature (Type ID 0x28)
Sourcepub fn verify_primary_key_binding<V, K>(
&self,
signer: &V,
signee: &K,
) -> Result<()>
pub fn verify_primary_key_binding<V, K>( &self, signer: &V, signee: &K, ) -> Result<()>
Verifies a primary key binding signature, or “back signature” (which links the primary to a signing subkey).
The subkey is expected as signer, the primary key as signee.
Allowed signature types are:
- Primary Key Binding Signature (type ID 0x19)
Sourcepub fn verify_key<V>(&self, key: &V) -> Result<()>where
V: VerifyingKey + Serialize,
pub fn verify_key<V>(&self, key: &V) -> Result<()>where
V: VerifyingKey + Serialize,
Verifies a direct key signature or a revocation.
Sourcepub fn verify_key_third_party<V, K>(&self, signee: &K, signer: &V) -> Result<()>
pub fn verify_key_third_party<V, K>(&self, signee: &K, signer: &V) -> Result<()>
Verifies a (possibly third-party) direct key signature or a revocation.
Allowed signature types are:
- Direct Key Signature (Type ID 0x1F)
- Key Revocation Signature (Type ID 0x20)
Sourcepub fn is_certification(&self) -> bool
pub fn is_certification(&self) -> bool
Returns if the signature is a certification or not.
Sourcepub fn key_expiration_time(&self) -> Option<Duration>
pub fn key_expiration_time(&self) -> Option<Duration>
If the hashed area contains any KeyExpirationTime subpacket, then this
returns Some(Duration) of the first KeyExpirationTime subpacket encountered.
If the hashed area contains no KeyExpirationTime subpacket, this returns None.
(Note that a return value of Some(Duration(0)) also means that no key expiration time
applies to the target component. This corresponds to a different wire-format
representation, but is semantically equivalent to None.)
pub fn signature_expiration_time(&self) -> Option<Duration>
pub fn created(&self) -> Option<Timestamp>
pub fn issuer_key_id(&self) -> Vec<&KeyId>
pub fn issuer_fingerprint(&self) -> Vec<&Fingerprint>
pub fn preferred_symmetric_algs(&self) -> &[SymmetricKeyAlgorithm]
pub fn preferred_aead_algs(&self) -> &[(SymmetricKeyAlgorithm, AeadAlgorithm)]
pub fn preferred_hash_algs(&self) -> &[HashAlgorithm]
pub fn preferred_compression_algs(&self) -> &[CompressionAlgorithm]
pub fn key_server_prefs(&self) -> &[u8] ⓘ
pub fn key_flags(&self) -> KeyFlags
pub fn features(&self) -> Option<&Features>
pub fn revocation_reason_code(&self) -> Option<&RevocationCode>
pub fn revocation_reason_string(&self) -> Option<&Bytes>
pub fn is_primary(&self) -> bool
pub fn is_revocable(&self) -> bool
pub fn embedded_signature(&self) -> Option<&Signature>
pub fn preferred_key_server(&self) -> Option<&str>
pub fn notations(&self) -> Vec<&Notation>
pub fn revocation_key(&self) -> Option<&RevocationKey>
Sourcepub fn signers_userid(&self) -> Option<&Bytes>
pub fn signers_userid(&self) -> Option<&Bytes>
Gets the user id of the signer
Note that the user id may not be valid utf-8, if it was created using a different encoding. But since the RFC describes every text as utf-8 it is up to the caller whether to error on non utf-8 data.
pub fn policy_uri(&self) -> Option<&str>
pub fn trust_signature(&self) -> Option<(u8, u8)>
pub fn regular_expression(&self) -> Option<&Bytes>
pub fn exportable_certification(&self) -> bool
Trait Implementations§
impl Eq for Signature
Source§impl PacketTrait for Signature
impl PacketTrait for Signature
fn packet_header(&self) -> &PacketHeader
fn packet_header_version(&self) -> PacketHeaderVersion
fn tag(&self) -> Tag
Source§fn to_writer_with_header<W: Write>(&self, writer: &mut W) -> Result<()>
fn to_writer_with_header<W: Write>(&self, writer: &mut W) -> Result<()>
Source§fn write_len_with_header(&self) -> usize
fn write_len_with_header(&self) -> usize
to_writer_with_header.impl StructuralPartialEq for Signature
Auto Trait Implementations§
impl !Freeze for Signature
impl RefUnwindSafe for Signature
impl Send for Signature
impl Sync for Signature
impl Unpin for Signature
impl UnsafeUnpin for Signature
impl UnwindSafe for Signature
Blanket Implementations§
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,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.