Skip to main content

Signature

Struct Signature 

Source
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

Source

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

Source

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!

Source

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!

Source

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).

Source

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.

Source

pub fn unknown( packet_header: PacketHeader, version: SignatureVersion, data: Bytes, ) -> Self

Create a signature of unknown version

Source

pub fn from_config( config: SignatureConfig, signed_hash_value: [u8; 2], signature: SignatureBytes, ) -> Result<Self>

Source

pub fn config(&self) -> Option<&SignatureConfig>

Returns the SignatureConfig if this is a known signature format.

Source

pub fn unhashed_subpacket_push(&mut self, subpacket: Subpacket) -> Result<()>

Appends a subpacket at the back of the unhashed area

Source

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

Source

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

Source

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.

Source

pub fn version(&self) -> SignatureVersion

Returns the SignatureVersion.

Source

pub fn typ(&self) -> Option<SignatureType>

Returns what kind of signature this is.

Source

pub fn hash_alg(&self) -> Option<HashAlgorithm>

The used HashAlgorithm.

Source

pub fn signature(&self) -> Option<&SignatureBytes>

Returns the actual byte level signature.

Source

pub fn signed_hash_value(&self) -> Option<[u8; 2]>

Source

pub fn verify<R>(&self, key: &impl VerifyingKey, data: R) -> Result<()>
where R: Read,

Verify this signature.

Source

pub fn verify_certification<V>( &self, key: &V, tag: Tag, id: &impl Serialize, ) -> Result<()>

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)
Source

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)
Source

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)
Source

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)
Source

pub fn verify_key<V>(&self, key: &V) -> Result<()>

Verifies a direct key signature or a revocation.

Source

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)
Source

pub fn is_certification(&self) -> bool

Returns if the signature is a certification or not.

Source

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.)

Source

pub fn signature_expiration_time(&self) -> Option<Duration>

Source

pub fn created(&self) -> Option<Timestamp>

Source

pub fn issuer_key_id(&self) -> Vec<&KeyId>

Source

pub fn issuer_fingerprint(&self) -> Vec<&Fingerprint>

Source

pub fn preferred_symmetric_algs(&self) -> &[SymmetricKeyAlgorithm]

Source

pub fn preferred_aead_algs(&self) -> &[(SymmetricKeyAlgorithm, AeadAlgorithm)]

Source

pub fn preferred_hash_algs(&self) -> &[HashAlgorithm]

Source

pub fn preferred_compression_algs(&self) -> &[CompressionAlgorithm]

Source

pub fn key_server_prefs(&self) -> &[u8]

Source

pub fn key_flags(&self) -> KeyFlags

Source

pub fn features(&self) -> Option<&Features>

Source

pub fn revocation_reason_code(&self) -> Option<&RevocationCode>

Source

pub fn revocation_reason_string(&self) -> Option<&Bytes>

Source

pub fn is_primary(&self) -> bool

Source

pub fn is_revocable(&self) -> bool

Source

pub fn embedded_signature(&self) -> Option<&Signature>

Source

pub fn preferred_key_server(&self) -> Option<&str>

Source

pub fn notations(&self) -> Vec<&Notation>

Source

pub fn revocation_key(&self) -> Option<&RevocationKey>

Source

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.

Source

pub fn policy_uri(&self) -> Option<&str>

Source

pub fn trust_signature(&self) -> Option<(u8, u8)>

Source

pub fn regular_expression(&self) -> Option<&Bytes>

Source

pub fn exportable_certification(&self) -> bool

Trait Implementations§

Source§

impl Clone for Signature

Source§

fn clone(&self) -> Signature

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Signature

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Signature

Source§

impl From<Signature> for Packet

Source§

fn from(other: Signature) -> Packet

Converts to this type from the input type.
Source§

impl PacketTrait for Signature

Source§

fn packet_header(&self) -> &PacketHeader

Source§

fn packet_header_version(&self) -> PacketHeaderVersion

Source§

fn tag(&self) -> Tag

Source§

fn to_writer_with_header<W: Write>(&self, writer: &mut W) -> Result<()>

Write this packet including the packet header.
Source§

fn write_len_with_header(&self) -> usize

Length in bytes used when calling to_writer_with_header.
Source§

impl PartialEq for Signature

Source§

fn eq(&self, other: &Signature) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Signature

Source§

fn to_writer<W: Write>(&self, writer: &mut W) -> Result<()>

Source§

fn write_len(&self) -> usize

Source§

fn to_bytes(&self) -> Result<Vec<u8>>

Source§

impl StructuralPartialEq for Signature

Source§

impl TryFrom<Packet> for Signature

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(other: Packet) -> Result<Signature, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .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
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V