Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.4.0+

Example: Mime.GetDecryptCertInfo method

Demonstrates the GetDecryptCertInfo method.

Chilkat Rust Downloads

Rust

let mime = chilkat::Mime::new();

// Load MIME that is has Content-Type like this:
// Content-Type: application/pkcs7-mime; smime-type="enveloped-data"; name="smime.p7m"; smime-type="enveloped-data"
if mime.load_mime_file("qa_data/mime/enveloped_data.eml").is_err() {
    println!("{}", mime.last_error_text());
    return;
}

// Get information about the certificate that would be needed to decrypt.
// An enveloped-data can potentially be decrypted by multiple certificates if it was encrypted in a way that allows it,
// but in most cases, only a single certificate with associated private key (that of the message recipient) is possible.
let json = chilkat::JsonObject::new();
if mime.get_decrypt_cert_info(&json).is_err() {
    println!("{}", mime.last_error_text());
    return;
}

json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());

// Sample output:

// {
//   "recipientInfo": [
//     {
//       "serial": "****",
//       "issuerCN": "****"
//     }
//   ]
// }

// Get each certificate's information like this:

let mut i = 0;
let count = json.size_of_array("recipientInfo");
while i < count {
    json.set_i(i);
    let _ = json.string_of("recipientInfo[i].serial").unwrap_or_default();
    let _ = json.string_of("recipientInfo[i].issuerCN").unwrap_or_default();
    i = i + 1;
}