pub struct X509CertificateBuilder { /* private fields */ }
Expand description

Interface for constructing new X.509 certificates.

This holds fields for various certificate metadata and allows you to incrementally derive a new X.509 certificate.

The certificate is populated with defaults:

  • The serial number is 1.
  • The time validity is now until 1 hour from now.
  • There is no issuer. If no attempt is made to define an issuer, the subject will be copied to the issuer field and this will be a self-signed certificate.

This type can also be used to produce certificate signing requests. In this mode, only the subject value and additional registered attributes are meaningful.

Implementations§

source§

impl X509CertificateBuilder

source

pub fn new() -> Self

👎Deprecated

Deprecated. Use Self::default() instead.

source

pub fn subject(&mut self) -> &mut Name

Obtain a mutable reference to the subject Name.

The type has functions that will allow you to add attributes with ease.

source

pub fn issuer(&mut self) -> &mut Name

Obtain a mutable reference to the issuer Name.

If no issuer has been created yet, an empty one will be created.

source

pub fn serial_number(&mut self, value: i64)

Set the serial number for the certificate.

source

pub fn extensions(&self) -> &Extensions

Obtain the raw certificate extensions.

source

pub fn extensions_mut(&mut self) -> &mut Extensions

Obtain a mutable reference to raw certificate extensions.

source

pub fn add_extension_der_data( &mut self, oid: Oid, critical: bool, data: impl AsRef<[u8]> )

Add an extension to the certificate with its value as pre-encoded DER data.

source

pub fn validity_duration(&mut self, duration: Duration)

Set the expiration time in terms of Duration since its currently set start time.

source

pub fn constraint_not_ca(&mut self)

Add a basic constraint extension that this isn’t a CA certificate.

source

pub fn key_usage(&mut self, key_usage: KeyUsage)

Add a key usage extension.

source

pub fn add_csr_attribute(&mut self, attribute: Attribute)

Add an [Attribute] to a future certificate signing requests.

Has no effect on regular certificate creation: only if creating certificate signing requests.

source

pub fn create_with_key_pair( &self, key_pair: &InMemorySigningKeyPair ) -> Result<CapturedX509Certificate, Error>

Create a new certificate given settings using the provided key pair.

source

pub fn create_with_random_keypair( &self, key_algorithm: KeyAlgorithm ) -> Result<(CapturedX509Certificate, InMemorySigningKeyPair), Error>

Create a new certificate given settings, using a randomly generated key pair.

source

pub fn create_certificate_signing_request( &self, signer: &dyn KeyInfoSigner ) -> Result<CertificationRequest, Error>

Create a new certificate signing request (CSR).

The CSR is derived according to the process defined in RFC 2986 Section 3. Essentially, we collect metadata about the request, sign that metadata using a provided signing/private key, then attach the signature to form a complete certification request.

Trait Implementations§

source§

impl Default for X509CertificateBuilder

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.