quantcrypt::certificates

Struct Certificate

source
pub struct Certificate { /* private fields */ }
Expand description

A certificate

§Example

use quantcrypt::certificates::Certificate;
let pem_bytes = include_bytes!("../../test/data_old/MlDsa44EcdsaP256SHA256-2.16.840.1.114027.80.8.1.4_ta.pem");
let pem = std::str::from_utf8(pem_bytes).unwrap().trim();
let cert = Certificate::from_pem(pem).unwrap();
assert!(cert.verify_self_signed().unwrap());

Implementations§

source§

impl Certificate

source

pub fn to_der(&self) -> Result<Vec<u8>, QuantCryptError>

Convert the certificate to DER format bytes

§Returns

The DER format bytes

source

pub fn to_pem(&self) -> Result<String, QuantCryptError>

Convert the certificate to PEM format

§Returns

The PEM format certificate as a string

source

pub fn from_der(der: &[u8]) -> Result<Certificate, QuantCryptError>

Create a certificate from DER format bytes

§Arguments
  • der - The DER format bytes
§Returns

The new certificate

§Errors

CertificateError::InvalidCertificate will be returned if the certificate is invalid

source

pub fn from_pem(pem: &str) -> Result<Certificate, QuantCryptError>

Create a certificate from a PEM format string

§Arguments
  • pem - The PEM format string
§Returns

The new certificate

§Errors

CertificateError::InvalidCertificate will be returned if the certificate is invalid

source

pub fn get_subject(&self) -> RdnSequence

Get the subject name

§Returns

The subject name

source

pub fn get_issuer(&self) -> RdnSequence

Get the issuer name

§Returns

The issuer name

source

pub fn get_serial_number(&self) -> SerialNumber

Get the serial number

§Returns

The serial number

source

pub fn get_subject_key_identifier( &self, ) -> Result<SubjectKeyIdentifier, QuantCryptError>

Get the subject key identifier

§Returns

The subject key identifier

source

pub fn verify_self_signed(&self) -> Result<bool, QuantCryptError>

Verify that the certificate is self-signed

§Returns

True if the certificate is self-signed, false otherwise

source

pub fn get_public_key(&self) -> Result<PublicKey, QuantCryptError>

Get the public key

§Returns

The public key

source

pub fn verify_child(&self, child: &Certificate) -> Result<bool, QuantCryptError>

Verify that the specified certificate is a child of this certificate.

This checks that the specified child certificate has the same issuer as this certificate’s subject, that the child’s Subject Key Identifier matches the Authority Key Identifier of this certificate, and that the child’s signature is valid.

§Arguments
  • child - The child certificate
§Returns

True if the child certificate is a child of this certificate, false otherwise

source

pub fn from_file(path: &str) -> Result<Certificate, QuantCryptError>

Load a certificate from the specified file. The file can be in either DER or PEM format.

§Arguments
  • path - The path to the file
§Returns

The certificate

source

pub fn to_der_file(&self, path: &str) -> Result<(), QuantCryptError>

Save the certificate to the specified file in DER format

§Arguments
  • path - The path to the file
source

pub fn to_pem_file(&self, path: &str) -> Result<(), QuantCryptError>

Save the certificate to the specified file in PEM format

§Arguments
  • path - The path to the file
source

pub fn is_identified_by(&self, rid: &RecipientIdentifier) -> bool

Check if this certificate is identified by the specified recipient identifier

This could match by either issuer and serial number or subject key identifier

§Arguments
  • rid - The recipient identifier
§Returns

True if the certificate is identified by the recipient identifier, false otherwise

source

pub fn is_valid(&self) -> bool

Check if this certificate is valid

§Returns

True if the certificate is valid, false otherwise

source

pub fn is_key_encipherment_enabled(&self) -> bool

Check if key encipherment is enabled

§Returns

True if key encipherment is enabled, false otherwise

source

pub fn get_public_key_oid(&self) -> String

Get the OID of algorithm used for the public key

§Returns

The OID of the algorithm used for the public key

source

pub fn get_signature_oid(&self) -> String

Get the OID of algorithm used for the signature

§Returns

The OID of the algorithm used for the signature

source

pub fn get_public_key_oid_friendly_name(&self) -> String

Get the friendly name of the algorithm used for the public key

§Returns

The friendly name of the algorithm used for the public key

Trait Implementations§

source§

impl Clone for Certificate

source§

fn clone(&self) -> Certificate

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
source§

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

source§

fn vzip(self) -> V