Skip to main content

CertificateWithDer

Struct CertificateWithDer 

Source
pub struct CertificateWithDer<T> { /* private fields */ }
Expand description

A certificate together with the DER it was decoded from.

Hand this to validate_path instead of a bare Certificate and signature verification uses the bytes the issuer actually signed, taken as a subslice, rather than rebuilding them with an encoder. That is both faster — re-encoding was measured at 59% of everything path validation does — and not subject to the faithfulness assumption described on tbs_der_slice.

Generic over the byte container so it costs nothing it need not: &[u8] to borrow a buffer the caller owns, Vec<u8> to take ownership, or any other AsRef<[u8]>.

§Examples

let held = CertificateWithDer::from_der(der)?;
assert_eq!(held.certificate().tbs_certificate().version(), Default::default());
// The signed bytes are a subslice of what was handed in.
assert!(held.tbs_der().len() < der.len());

Implementations§

Source§

impl<T: AsRef<[u8]>> CertificateWithDer<T>

Source

pub fn from_der(der: T) -> Result<Self>

Decodes der and remembers where its TBSCertificate is.

Parsing and slicing happen together, which is the point: a constructor that accepted a Certificate and some bytes separately could be handed one certificate’s parse beside another’s DER, and the signature check would then verify the wrong message against the right key.

§Errors

Returns Error::Der if der is not a single DER-encoded certificate, trailing bytes included.

Source

pub fn certificate(&self) -> &Certificate

The parsed certificate.

Source

pub fn der(&self) -> &[u8] ⓘ

The whole certificate’s DER, as supplied.

Source

pub fn tbs_der(&self) -> &[u8] ⓘ

The TBSCertificate bytes the issuer signed.

Source

pub fn into_parts(self) -> (T, Certificate)

Gives back the container and the parse.

Trait Implementations§

Source§

impl<T: Clone> Clone for CertificateWithDer<T>

Source§

fn clone(&self) -> Self

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<T: Debug> Debug for CertificateWithDer<T>

Source§

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

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

impl<T> DecodeCertificate for CertificateWithDer<T>
where T: AsRef<[u8]> + From<Vec<u8>>,

Source§

fn decode_certificate(der: Vec<u8>) -> Result<Self>

Decodes one DER-encoded certificate. Read more
Source§

impl<T: AsRef<[u8]>> PathCertificate for CertificateWithDer<T>

Source§

fn certificate(&self) -> &Certificate

The certificate itself.
Source§

fn certificate_der(&self) -> Option<&[u8]>

The certificate’s own DER, when the element kept it. Read more
Source§

fn signed_tbs(&self) -> Option<&[u8]>

The exact TBSCertificate bytes the issuer signed, when they are available. Read more
Source§

impl<T: AsRef<[u8]>> RetainedCertificate for CertificateWithDer<T>

Source§

fn der(&self) -> &[u8] ⓘ

The certificate as it was received, octet for octet. Read more

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

Source§

type Output = T

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.