Rust Requires Chilkat v11.0.0+
Rust
Verify a .p7m and get Algorithm Information
See more Digital Signatures Examples
Demonstrates how to verify a .p7m and then examine the algorithms used by the signature.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let crypt = chilkat::Crypt2::new();
let in_file = "qa_data/p7m/brainpoolP256r1.p7m".to_string();
let out_file = "qa_output/something.dat".to_string();
// Verify and extract the signed data.
if crypt.verify_p7_m(&in_file, &out_file).is_err() {
println!("{}", crypt.last_error_text());
return;
}
// Examine details about the signature(s)
let json = chilkat::JsonObject::new();
crypt.get_last_json_data(&json);
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());
// Sample output
// {
// "pkcs7": {
// "verify": {
// "digestAlgorithms": [
// "sha256"
// ],
// "signerInfo": [
// {
// "cert": {
// "serialNumber": "FFFFE552B302FFFFFF1E34C3ACEB2FFFF",
// "issuerCN": "The common name of the cert...",
// "issuerDN": "",
// "digestAlgOid": "2.16.840.1.101.3.4.2.1",
// "digestAlgName": "SHA256"
// },
// "contentType": "1.2.840.113549.1.7.1",
// "signingTime": "190409140500Z",
// "messageDigest": "lQe9If7vZKFf/NlSYu5Esmlw3phVK/RFsbbb1uH73t8=",
// "signingAlgOid": "1.2.840.10045.4.3.2",
// "signerDigest": "lQe9If7vZKFf/NlSYu5Esmlw3phVK/RFsbbb1uH73t8=",
// "authAttr": [
// {
// "oid": "1.2.840.113549.1.9.3",
// "oidName": "contentType"
// },
// {
// "oid": "1.2.840.113549.1.9.5",
// "oidName": "signingTime"
// },
// {
// "oid": "1.2.840.113549.1.9.52",
// "oidName": "1.2.840.113549.1.9.52",
// "der": "MBs ... AwI="
// },
// {
// "oid": "1.2.840.113549.1.9.4",
// "oidName": "messageDigest"
// },
// {
// "oid": "1.2.840.113549.1.9.16.2.47",
// "oidName": "signingCertificateV2",
// "der": "MCYw .. 7PlQ=="
// },
// {
// "oid": "1.2.840.113549.1.9.20",
// "oidName": "1.2.840.113549.1.9.20"
// }
// ]
// }
// ]
// }
// }
// }
// Code for parsing the above JSON...
let mut i: i32 = 0;
let mut count_i: i32 = 0;
let mut j: i32 = 0;
let mut count_j: i32 = 0;
i = 0;
count_i = json.size_of_array("pkcs7.verify.digestAlgorithms");
while i < count_i {
json.set_i(i);
let _ = json.string_of("pkcs7.verify.digestAlgorithms[i]").unwrap_or_default();
i = i + 1;
}
i = 0;
count_i = json.size_of_array("pkcs7.verify.signerInfo");
while i < count_i {
json.set_i(i);
let _ = json.string_of("pkcs7.verify.signerInfo[i].cert.serialNumber").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].cert.issuerCN").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].cert.issuerDN").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].cert.digestAlgOid").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].cert.digestAlgName").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].contentType").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].signingTime").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].messageDigest").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].signingAlgOid").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].signerDigest").unwrap_or_default();
j = 0;
count_j = json.size_of_array("pkcs7.verify.signerInfo[i].authAttr");
while j < count_j {
json.set_j(j);
let _ = json.string_of("pkcs7.verify.signerInfo[i].authAttr[j].oid").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].authAttr[j].oidName").unwrap_or_default();
let _ = json.string_of("pkcs7.verify.signerInfo[i].authAttr[j].der").unwrap_or_default();
j = j + 1;
}
i = i + 1;
}
println!("Success!");