Struct sequoia_openpgp::cert::raw::RawCert

source ·
pub struct RawCert<'a> { /* private fields */ }
Expand description

A mostly unparsed Cert.

This data structure contains the unparsed packets for a certificate or key. The packet sequence is well formed in the sense that the sequence of tags conforms to the Transferable Public Key grammar or Transferable Secret Key grammar, and that it can extract the primary key’s fingerprint. Beyond that, the packets are not guaranteed to be valid.

This data structure exists to quickly split a large keyring, and only parse those certificates that appear to be relevant.

Implementations§

source§

impl<'a> RawCert<'a>

source

pub fn as_bytes(&'a self) -> &'a [u8]

Returns the certificate’s bytes.

If you want an individual packet’s bytes, use RawCert::packet or RawCert::packets, and then call RawPacket::as_bytes.

source

pub fn fingerprint(&self) -> Fingerprint

Returns the certificate’s fingerprint.

source

pub fn keyid(&self) -> KeyID

Returns the certificate’s Key ID.

source

pub fn packet(&self, i: usize) -> Option<RawPacket<'_>>

Returns the ith packet.

source

pub fn packets(&self) -> impl Iterator<Item = RawPacket<'_>>

Returns an iterator over each raw packet.

source

pub fn count(&self) -> usize

Returns the number of packets.

source

pub fn keys(&self) -> KeyIter<'_, PublicParts, UnspecifiedRole>

Returns an iterator over the certificate’s keys.

Note: this parses the key packets, but it does not verify any binding signatures. As such, this can only be used as part of a precheck. If the certificate appears to match, then the caller must convert the RawCert to a Cert or a ValidCert, depending on the requirements, and perform the check again.

Use subkeys to just return the subkeys. This function also changes the return type. Instead of the iterator returning a Key whose role is key::UnspecifiedRole, the role is key::SubordinateRole.

§Examples
use sequoia_openpgp as openpgp;
use openpgp::cert::raw::RawCertParser;
use openpgp::parse::Parse;
for cert in RawCertParser::from_bytes(&bytes)? {
    /// Ignore corrupt and invalid certificates.
    let cert = if let Ok(cert) = cert {
        cert
    } else {
        continue;
    };

    // Iterate over the keys.  Note: this parses the Key
    // packets.
    for key in cert.keys() {
        println!("{}", key.fingerprint());
    }
}
source

pub fn primary_key(&self) -> Key<PublicParts, PrimaryRole>

Returns the certificate’s primary key.

Note: this parses the primary key packet, but it does not verify any binding signatures. As such, this can only be used as part of a precheck. If the certificate appears to match, then the caller must convert the RawCert to a Cert or a ValidCert, depending on the requirements, and perform the check again.

source

pub fn userids(&self) -> impl Iterator<Item = UserID> + '_

Returns the certificate’s User IDs.

Note: this parses the User ID packets, but it does not verify any binding signatures. That is, there is no guarantee that the User IDs should actually be associated with the primary key. As such, this can only be used as part of a precheck. If a User ID appears to match, then the caller must convert the RawCert to a Cert or a ValidCert, depending on the requirements, and perform the check again.

Trait Implementations§

source§

impl<'a> Clone for RawCert<'a>

source§

fn clone(&self) -> RawCert<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for RawCert<'a>

source§

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

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

impl<'a> Marshal for RawCert<'a>

source§

fn serialize(&self, o: &mut dyn Write) -> Result<()>

Writes a serialized version of the object to o.
source§

fn export(&self, o: &mut dyn Write) -> Result<()>

Exports a serialized version of the object to o. Read more
source§

impl<'a> Parse<'a, RawCert<'a>> for RawCert<'a>

source§

fn from_buffered_reader<R>(reader: R) -> Result<RawCert<'a>>
where R: BufferedReader<Cookie> + 'a,

Returns the first RawCert encountered in the reader.

Returns an error if there are multiple certificates.

source§

fn from_reader<R: 'a + Read + Send + Sync>(reader: R) -> Result<Self>

Returns the first RawCert encountered in the reader.

Returns an error if there are multiple certificates.

source§

fn from_file<P: AsRef<Path>>(path: P) -> Result<T>

Reads from the given file. Read more
source§

fn from_bytes<D: AsRef<[u8]> + ?Sized + Send + Sync>(data: &'a D) -> Result<T>

Reads from the given slice. Read more
source§

impl<'a> PartialEq for RawCert<'a>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> TryFrom<&RawCert<'a>> for Cert

§

type Error = Error

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

fn try_from(c: &RawCert<'_>) -> Result<Self>

Performs the conversion.
source§

impl<'a> TryFrom<RawCert<'a>> for Cert

§

type Error = Error

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

fn try_from(c: RawCert<'_>) -> Result<Self>

Performs the conversion.
source§

impl<'a> Eq for RawCert<'a>

Auto Trait Implementations§

§

impl<'a> !Freeze for RawCert<'a>

§

impl<'a> RefUnwindSafe for RawCert<'a>

§

impl<'a> Send for RawCert<'a>

§

impl<'a> Sync for RawCert<'a>

§

impl<'a> Unpin for RawCert<'a>

§

impl<'a> UnwindSafe for RawCert<'a>

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<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T