Rust
Rust
ScMinidriver - List Certificates on a Smart Card or USB Token
See more ScMinidriver Examples
Gets a list of certificates contained on a smart card or USB token.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let scmd = chilkat::ScMinidriver::new();
// Reader names (smart card readers or USB tokens) can be discovered
// via PCSC List Readers or PCSC Find Smart Cards
let reader_name = "SCM Microsystems Inc. SCR33x USB Smart Card Reader 0".to_string();
if scmd.acquire_context(&reader_name).is_err() {
println!("{}", scmd.last_error_text());
return;
}
let st_certs = chilkat::StringTable::new();
// We can choose one of the following items of information to get for each certificate:
// "subjectDN" -- Return the full distinguished name of the cert.
// "subjectDN_withTags" -- Same as above, but in a format that includes the subject part tags, such as the "CN=" in "CN=something"
// "subjectCN" -- Return just the common name part of the certificate's subject.
// "serial" -- Return the certificate serial number.
// "serial:issuerCN" -- return the certificate serial number + the issuer's common name, delimited with a colon char.
let cert_part = "subjectCN".to_string();
if scmd.list_certs(&cert_part, &st_certs).is_err() {
println!("{}", scmd.last_error_text());
return;
}
let num_certs = st_certs.count();
let mut i = 0;
while i < num_certs {
println!("{}: {}", i, st_certs.string_at(i).unwrap_or_default());
i = i + 1;
}
// Delete the context when finished with the card.
if scmd.delete_context().is_err() {
println!("{}", scmd.last_error_text());
}