CertificateBuilder

Struct CertificateBuilder 

Source
pub struct CertificateBuilder<'a> { /* private fields */ }
Expand description

A builder for creating X.509 certificates

§Example:

use quantcrypt::certificates::CertificateBuilder;
use quantcrypt::dsas::DsaAlgorithm;
use quantcrypt::kems::KemAlgorithm;
use quantcrypt::certificates::Profile;
use quantcrypt::dsas::DsaKeyGenerator;
use quantcrypt::kems::KemKeyGenerator;
use quantcrypt::certificates::CertValidity;

// Create a TA key pair
let (pk_root, sk_root) = DsaKeyGenerator::new(DsaAlgorithm::MlDsa44).generate().unwrap();

let profile = Profile::Root;
let serial_no = None; // This will generate a random serial number
let validity = CertValidity::new(None, "2035-01-01T00:00:00Z").unwrap(); // Not before is now
let subject = "CN=example.com".to_string();
let cert_public_key = pk_root.clone();
let signer = &sk_root;

// Create the TA certificate builder
let builder = CertificateBuilder::new(
  profile,
  serial_no,
  validity.clone(),
  subject.clone(),
  cert_public_key,
  signer).unwrap();
let cert_root = builder.build().unwrap();
assert!(cert_root.verify_self_signed().unwrap());
// Create a leaf (EE) key pair for KEM
let (pk_kem, sk_kem) = KemKeyGenerator::new(KemAlgorithm::MlKem512).generate().unwrap();
let builder = CertificateBuilder::new(Profile::Leaf {
  issuer: cert_root.get_subject(),
  enable_key_agreement: false,
  enable_key_encipherment: true,
}, serial_no,
  validity,
  subject,
  pk_kem,
  signer).unwrap();
let cert_kem = builder.build().unwrap();

// It's not self signed so verification as self signed should fail
assert!(!cert_kem.verify_self_signed().unwrap());

// But it should verify against the root
assert!(cert_root.verify_child(&cert_kem).unwrap());

Implementations§

Source§

impl<'a> CertificateBuilder<'a>

Source

pub fn new( profile: Profile, serial_number: Option<[u8; 20]>, validity: CertValidity, subject: String, cert_public_key: PublicKey, signer: &'a PrivateKey, ) -> Result<CertificateBuilder<'a>, QuantCryptError>

Create a new certificate builder

Source

pub fn add_extension( &mut self, extension: impl AsExtension, ) -> Result<&mut Self, QuantCryptError>

Source

pub fn build(self) -> Result<Certificate, QuantCryptError>

Auto Trait Implementations§

§

impl<'a> Freeze for CertificateBuilder<'a>

§

impl<'a> RefUnwindSafe for CertificateBuilder<'a>

§

impl<'a> Send for CertificateBuilder<'a>

§

impl<'a> Sync for CertificateBuilder<'a>

§

impl<'a> Unpin for CertificateBuilder<'a>

§

impl<'a> UnwindSafe for CertificateBuilder<'a>

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V