Struct OcspRequestBuilder

Source
pub struct OcspRequestBuilder { /* private fields */ }
Available on crate feature builder only.
Expand description

X509 OCSP Request builder

use der::Decode;
use sha1::Sha1;
use x509_cert::{serial_number::SerialNumber, Certificate};
use x509_ocsp::builder::OcspRequestBuilder;
use x509_ocsp::{ext::Nonce, Request};

let issuer = Certificate::from_der(ISSUER_DER).unwrap();
let cert = Certificate::from_der(CERT_DER).unwrap();

let req = OcspRequestBuilder::default()
    .with_request(Request::from_cert::<Sha1>(&issuer, &cert).unwrap())
    .build();

let mut rng = rand::thread_rng();

let req = OcspRequestBuilder::default()
    .with_request(Request::from_issuer::<Sha1>(&issuer, SerialNumber::from(2usize)).unwrap())
    .with_request(Request::from_issuer::<Sha1>(&issuer, SerialNumber::from(3usize)).unwrap())
    .with_request(Request::from_issuer::<Sha1>(&issuer, SerialNumber::from(4usize)).unwrap())
    .with_extension(Nonce::generate(&mut rng, 32).unwrap())
    .unwrap()
    .build();

let mut signer = rsa_signer();
let signer_cert_chain = vec![cert.clone()];
let req = OcspRequestBuilder::default()
    .with_request(Request::from_cert::<Sha1>(&issuer, &cert).unwrap())
    .with_extension(Nonce::generate(&mut rng, 32).unwrap())
    .unwrap()
    .sign(&mut signer, Some(signer_cert_chain))
    .unwrap();

Implementations§

Source§

impl OcspRequestBuilder

Source

pub fn new(version: Version) -> Self

Returns an OcspRequestBuilder with the specified Version

Source

pub fn with_requestor_name(self, requestor_name: GeneralName) -> Self

Sets the requestor name as specified in RFC 6960 Section 4.1.1

Source

pub fn with_request(self, request: Request) -> Self

Adds a Request to the builder as defined in RFC 6960 Section 4.1.1.

Source

pub fn with_extension(self, ext: impl AsExtension) -> Result<Self, Error>

Adds a request extension as specified in RFC 6960 Section 4.4. Errors when the extension encoding fails.

Source

pub fn build(self) -> OcspRequest

Consumes the builder and returns an OcspRequest

Source

pub fn sign<S, Sig>( self, signer: &mut S, certificate_chain: Option<Vec<Certificate>>, ) -> Result<OcspRequest, Error>

Consumes the builder and returns a signed OcspRequest. Errors when the algorithm identifier encoding, message encoding, or signature generation fails.

Source

pub fn sign_with_rng<S, Sig>( self, signer: &mut S, rng: &mut impl CryptoRngCore, certificate_chain: Option<Vec<Certificate>>, ) -> Result<OcspRequest, Error>

Consumes the builder and returns a signed OcspRequest. Errors when the algorithm identifier encoding, message encoding, or signature generation fails.

Trait Implementations§

Source§

impl Clone for OcspRequestBuilder

Source§

fn clone(&self) -> OcspRequestBuilder

Returns a duplicate 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 Debug for OcspRequestBuilder

Source§

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

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

impl Default for OcspRequestBuilder

Source§

fn default() -> OcspRequestBuilder

Returns the “default value” for a type. 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 = 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.