Zig
Zig
Verify XML Digital Signature
See more XML Digital Signatures Examples
Verifies XML signatures in an XML file.Chilkat 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 sb_xml = try chilkat.StringBuilder.init();
defer sb_xml.deinit();
sb_xml.loadFile("qa_data/xml_dsig_verify/csioz_sample.xml", "utf-8") catch {
std.debug.print("Failed to load XML file.\n", .{});
return;
};
const dsig = try chilkat.XmlDSig.init();
defer dsig.deinit();
// First load the XML containing the signatures to be verified.
dsig.loadSignatureSb(sb_xml) catch {
std.debug.print("{s}\n", .{try dsig.getLastErrorText(alloc)});
return;
};
// It's possible that an XML document can contain multiple signatures.
// Each can be verified as follows:
var i: i32 = 0;
while (i < dsig.getNumSignatures()) {
// Select the Nth signature by setting the Selector property.
dsig.setSelector(i);
// The bVerifyReferenceDigests argument determines if we want
// to also verify each reference digest. If set to false,
// then only the SignedInfo part of the Signature is verified.
const b_verify_reference_digests = true;
const b_verified = if (dsig.verifySignature(b_verify_reference_digests)) true else |_| false;
std.debug.print("Signature {d} verified = {}\n", .{ i + 1, b_verified });
i = i + 1;
}
}