Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pdf = try chilkat.Pdf.init();
defer pdf.deinit();
// Load a PDF that has cryptographic signatures to be validated
pdf.loadFile("qa_data/pdf/sign_testing_1/helloSigned2.pdf") catch {
std.debug.print("{s}\n", .{try pdf.getLastErrorText(alloc)});
return;
};
// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
const sig_info = try chilkat.JsonObject.init();
defer sig_info.deinit();
// Iterate over each signature and validate each.
const num_signatures = pdf.getNumSignatures();
var validated: bool = false;
const cert = try chilkat.Cert.init();
defer cert.deinit();
var i: i32 = 0;
while (i < num_signatures) {
validated = if (pdf.verifySignature(i, sig_info)) true else |_| false;
std.debug.print("Signature {d} validated: {}\n", .{ i, validated });
// After calling VerifySignature, you can get the signer certificate by calling
// GetSignerCert with the same index.
if (pdf.getSignerCert(i, cert)) {
std.debug.print("PDF signer certificate: {s}\n", .{try cert.getSubjectDN(alloc)});
} else |_| {}
i = i + 1;
}
std.debug.print("Finished.\n", .{});
}