Zig
Zig
Extract XML from FatturaPA .p7m
See more Digital Signatures Examples
Demonstrates how to verify the signature and extract the XML from a FatturaPA .p7m 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 bd = try chilkat.BinData.init();
defer bd.deinit();
bd.loadFile("qa_data/p7m/IT01879020517_abc.xml.p7m") catch {
std.debug.print("Failed to load the .p7m file\n", .{});
return;
};
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
// Verify and extrct the payload contained within the .p7m.
// In this case, the payload is the FatturaPA XML.
// If successful, the resulting bd will contain only the XML.
crypt.opaqueVerifyBd(bd) catch {
std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
std.debug.print("Failed to extract and verify.\n", .{});
return;
};
// Save the XML to a file.
bd.writeFile("qa_output/zIT01879020517_abc.xml") catch {};
// Alternatively, load into an XML object and emit.
const xml = try chilkat.Xml.init();
defer xml.deinit();
xml.loadXml(try bd.getString(alloc, "utf-8")) catch {};
std.debug.print("{s}\n", .{try xml.getXml(alloc)});
}