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>
impl<T: AsRef<[u8]>> CertificateWithDer<T>
Sourcepub fn from_der(der: T) -> Result<Self>
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.
Sourcepub fn certificate(&self) -> &Certificate
pub fn certificate(&self) -> &Certificate
The parsed certificate.
Sourcepub fn into_parts(self) -> (T, Certificate)
pub fn into_parts(self) -> (T, Certificate)
Gives back the container and the parse.