Skip to main content

Certificate

Struct Certificate 

Source
pub struct Certificate { /* private fields */ }

Implementations§

Source§

impl Certificate

Source

pub fn from_der(der: &[u8]) -> Result<Self>

Examples found in repository?
examples/11_cms_cert_bag.rs (line 7)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::from_der(&support::fixture("test-cert.der"))?;
8    let encoded = Cms::encode_supporting_certificates(&[certificate])?;
9    let decoded = Cms::decode_all_certificates(&encoded)?;
10    println!("cms_len={} certs={}", encoded.len(), decoded.len());
11    Ok(())
12}
More examples
Hide additional examples
examples/05_trust_evaluate.rs (line 7)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::from_der(&support::fixture("test-cert.der"))?;
8    let policy = Policy::basic_x509()?;
9    let mut trust = Trust::new(&certificate, &[policy])?;
10    trust.set_anchor_certificates(&[certificate])?;
11    trust.set_anchor_certificates_only(true)?;
12    trust.set_network_fetch_allowed(false)?;
13    trust.evaluate()?;
14    println!("chain_len={}", trust.certificate_chain()?.len());
15    Ok(())
16}
Source

pub fn import_item( data: &[u8], file_name_or_extension: Option<&str>, format: ExternalFormat, item_type: ExternalItemType, ) -> Result<Self>

Examples found in repository?
examples/03_certificate_inspect.rs (lines 7-12)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::import_item(
8        &support::fixture("test-cert.pem"),
9        Some(".pem"),
10        ExternalFormat::Unknown,
11        ExternalItemType::Certificate,
12    )?;
13    let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14    println!(
15        "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16        certificate.subject_summary()?,
17        certificate.email_addresses()?,
18        certificate.serial_number()?.len(),
19        exported_pem.len()
20    );
21    Ok(())
22}
Source

pub fn export_item( &self, format: ExternalFormat, pem_armour: bool, ) -> Result<Vec<u8>>

Examples found in repository?
examples/03_certificate_inspect.rs (line 13)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::import_item(
8        &support::fixture("test-cert.pem"),
9        Some(".pem"),
10        ExternalFormat::Unknown,
11        ExternalItemType::Certificate,
12    )?;
13    let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14    println!(
15        "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16        certificate.subject_summary()?,
17        certificate.email_addresses()?,
18        certificate.serial_number()?.len(),
19        exported_pem.len()
20    );
21    Ok(())
22}
Source

pub fn from_pem(pem: &[u8]) -> Result<Self>

Examples found in repository?
examples/14_key_import_sign_verify.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let raw_key = PrivateKey::from_data(
8        &support::fixture("test-key-rsa.pkcs1.der"),
9        KeyType::Rsa,
10        2048,
11    )?;
12    let signature = raw_key.sign(
13        SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
14        b"security-rs",
15    )?;
16    let certificate = Certificate::from_pem(&support::fixture("test-cert.pem"))?;
17    let verified = certificate.public_key()?.verify_signature(
18        SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
19        b"security-rs",
20        &signature,
21    )?;
22    println!("signature_len={} verified={verified}", signature.len());
23    Ok(())
24}
Source

pub fn subject_summary(&self) -> Result<Option<String>>

Examples found in repository?
examples/02_identity_pkcs12.rs (line 13)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let identity = Identity::import_pkcs12_first(&support::fixture("test-identity.p12"), "password")?;
8    let certificate = identity.certificate()?;
9    println!(
10        "label={:?} chain_count={} subject={:?}",
11        identity.label()?,
12        identity.chain_count(),
13        certificate.subject_summary()?
14    );
15    Ok(())
16}
More examples
Hide additional examples
examples/03_certificate_inspect.rs (line 16)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::import_item(
8        &support::fixture("test-cert.pem"),
9        Some(".pem"),
10        ExternalFormat::Unknown,
11        ExternalItemType::Certificate,
12    )?;
13    let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14    println!(
15        "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16        certificate.subject_summary()?,
17        certificate.email_addresses()?,
18        certificate.serial_number()?.len(),
19        exported_pem.len()
20    );
21    Ok(())
22}
Source

pub fn common_name(&self) -> Result<Option<String>>

Source

pub fn email_addresses(&self) -> Result<Vec<String>>

Examples found in repository?
examples/03_certificate_inspect.rs (line 17)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::import_item(
8        &support::fixture("test-cert.pem"),
9        Some(".pem"),
10        ExternalFormat::Unknown,
11        ExternalItemType::Certificate,
12    )?;
13    let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14    println!(
15        "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16        certificate.subject_summary()?,
17        certificate.email_addresses()?,
18        certificate.serial_number()?.len(),
19        exported_pem.len()
20    );
21    Ok(())
22}
Source

pub fn normalized_subject_sequence(&self) -> Result<Vec<u8>>

Source

pub fn normalized_issuer_sequence(&self) -> Result<Vec<u8>>

Source

pub fn serial_number(&self) -> Result<Vec<u8>>

Examples found in repository?
examples/03_certificate_inspect.rs (line 18)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let certificate = Certificate::import_item(
8        &support::fixture("test-cert.pem"),
9        Some(".pem"),
10        ExternalFormat::Unknown,
11        ExternalItemType::Certificate,
12    )?;
13    let exported_pem = certificate.export_item(ExternalFormat::X509Certificate, true)?;
14    println!(
15        "subject={:?} emails={:?} serial_len={} exported_pem_len={}",
16        certificate.subject_summary()?,
17        certificate.email_addresses()?,
18        certificate.serial_number()?.len(),
19        exported_pem.len()
20    );
21    Ok(())
22}
Source

pub fn not_valid_before(&self) -> Result<Option<SystemTime>>

Source

pub fn not_valid_after(&self) -> Result<Option<SystemTime>>

Source

pub fn der_data(&self) -> Result<Vec<u8>>

Source

pub fn public_key(&self) -> Result<PublicKey>

Examples found in repository?
examples/14_key_import_sign_verify.rs (line 17)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let raw_key = PrivateKey::from_data(
8        &support::fixture("test-key-rsa.pkcs1.der"),
9        KeyType::Rsa,
10        2048,
11    )?;
12    let signature = raw_key.sign(
13        SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
14        b"security-rs",
15    )?;
16    let certificate = Certificate::from_pem(&support::fixture("test-cert.pem"))?;
17    let verified = certificate.public_key()?.verify_signature(
18        SignatureAlgorithm::RsaSignatureMessagePkcs1v15Sha256,
19        b"security-rs",
20        &signature,
21    )?;
22    println!("signature_len={} verified={verified}", signature.len());
23    Ok(())
24}

Trait Implementations§

Source§

impl Debug for Certificate

Source§

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

Formats the value using the given formatter. 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.