Sample code for 30+ languages & platforms
Zig

Verify the Timestamp Server Token (if any) while Validating a CMS Signature

Demonstrates how to also validate the timestamp server token (if any) while validating a CMS signature.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const crypt = try chilkat.Crypt2.init();
    defer crypt.deinit();

    // Tell Chilkat to also validate the timestamp token if a timestamp exists in the CMS message's unauthenticated attributes.
    const cms_options = try chilkat.JsonObject.init();
    defer cms_options.deinit();
    cms_options.updateBool("ValidateTimestampTokens", true) catch {};
    crypt.setCmsOptions(try cms_options.emit(alloc));

    const output_file = "qa_output/original.xml";
    const in_file = "qa_data/p7m/fattura_signature.xml.p7m";

    // Verify the signature and extract the contained file, which in this case is XML.
    crypt.verifyP7M(in_file, output_file) catch {
        std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Signature validated.\n", .{});
}