Zig
Zig
Verify XAdES with External File Reference
See more XML Digital Signatures Examples
Demonstrates how to validate an XML digital signature that contains a reference to an external file. (This is one way of doing it..)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.
// Load the XAdES file to be validated..
const sb_xml = try chilkat.StringBuilder.init();
defer sb_xml.deinit();
sb_xml.loadFile("qa_data/xml_dsig_valid_samples/externalFile/test.pdf.XAdES", "utf-8") catch {
std.debug.print("Failed to load XAdES input file.\n", .{});
return;
};
const validator = try chilkat.XmlDSig.init();
defer validator.deinit();
// Specify a set of absolute or relative directory paths to be searched for any external file references.
// Directory paths are separated by semicolon chars.
validator.setExternalRefDirs("qa_data/externalFiles;qa_data/xml_dsig_valid_samples/externalFile;c:/someOtherDir");
validator.loadSignatureSb(sb_xml) catch {
std.debug.print("{s}\n", .{try validator.getLastErrorText(alloc)});
return;
};
// Validate signatures as usual..
var i: i32 = 0;
while (i < validator.getNumSignatures()) {
validator.setSelector(i);
const valid = if (validator.verifySignature(true)) true else |_| false;
std.debug.print("Signature {d} and all reference digests OK = {}\n", .{ i + 1, valid });
i = i + 1;
}
}