Sample code for 30+ languages & platforms
Rust

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Rust Downloads

Rust

let cert_store = chilkat::CertStore::new();

// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
let read_only = false;
if cert_store.open_current_user_store(read_only).is_err() {
    println!("{}", cert_store.last_error_text());
    return;
}

let cert = chilkat::Cert::new();

let num_certs = cert_store.num_certificates();
let mut i = 0;

while i < num_certs {
    // Load the cert object with the Nth certificate.
    let _ = cert_store.get_cert(i, &cert);
    println!("{}: {}", i, cert.subject_cn());
    i = i + 1;
}