x509_certificate::certificate

Struct X509CertificateBuilder

Source
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 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> 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, 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.