Validator

Struct Validator 

Source
pub struct Validator { /* private fields */ }
Expand description

Attestation validator.

§Examples

let mut validator = attestation_validator::Validator::default();

validator.add_from_pem(std::fs::File::open("hsm-attestation-pem")?)?;

let extensions = validator.leaf_extensions()?;
let extension = extensions.get("1.3.6.1.4.1.41482.4.1")?;

Implementations§

Source§

impl Validator

Source

pub fn add_from_pem(&mut self, reader: impl Read + Seek) -> Result<()>

Adds one or more PEM-encoded certificates from the reader to the certificate chain.

Adding certificate triggers chain validation.

§Examples
let mut validator = attestation_validator::Validator::default();

validator.add_from_pem(std::fs::File::open("hsm-attestation-pem")?)?;
§Errors

Returns an error if PEM parsing fails or certificate chain validation fails.

Source

pub fn add_from_der(&mut self, der: Vec<u8>) -> Result<()>

Adds one raw, binary DER-encoded certificate to the certificate chain.

Adding certificate triggers chain validation.

§Examples
let mut validator = attestation_validator::Validator::default();

validator.add_from_der(std::fs::read("hsm-attestation-cert.cer")?)?;
§Errors

Returns an error if DER parsing fails or certificate chain validation fails.

Source

pub fn leaf_extensions(&self) -> Result<Extensions>

Returns extensions present in the last certificate in the chain (leaf).

§Examples
let mut validator = attestation_validator::Validator::default();

validator.add_from_pem(std::fs::File::open("hsm-attestation-pem")?)?;

let extensions = validator.leaf_extensions()?;
let extension = extensions.get("1.3.6.1.4.1.41482.4.1")?;
§Errors

Returns an error if DER parsing of the last certificate fails, if there are no certificates in the chain or no extensions.

Source

pub fn leaf_public_key(&self) -> Result<Vec<u8>>

Returns a raw, unparsed PKIX of the public key in ASN.1 DER form (see RFC 5280, Section 4.1).

§Examples
let mut validator = attestation_validator::Validator::default();

validator.add_from_pem(std::fs::File::open("hsm-attestation-pem")?)?;

let public_key_der = validator.leaf_public_key()?;
assert_eq!(public_key_der[0..3], [48, 42, 48]);
§Errors

Returns an error if DER parsing of the last certificate fails, if there are no certificates in the chain.

Trait Implementations§

Source§

impl Debug for Validator

Source§

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

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

impl Default for Validator

Source§

fn default() -> Validator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

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

Performs the conversion.