Rust
Rust
Get PDF Signer Certs
See more PDF Signatures Examples
This example demonstrates how to validate the signatures in a PDF and also shows how to getChilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let pdf = chilkat::Pdf::new();
// Load a PDF that has cryptographic signatures to be validated
if pdf.load_file("qa_data/pdf/sign_testing_1/helloSigned2.pdf").is_err() {
println!("{}", pdf.last_error_text());
return;
}
// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
let sig_info = chilkat::JsonObject::new();
// Iterate over each signature and validate each.
let num_signatures = pdf.num_signatures();
let mut validated = false;
let cert = chilkat::Cert::new();
let mut i = 0;
while i < num_signatures {
validated = pdf.verify_signature(i, &sig_info).is_ok();
println!("Signature {} validated: {}", i, validated);
// After calling VerifySignature, you can get the signer certificate by calling
// GetSignerCert with the same index.
if pdf.get_signer_cert(i, &cert).is_ok() {
println!("PDF signer certificate: {}", cert.subject_dn());
}
i = i + 1;
}
println!("Finished.");