Sample code for 30+ languages & platforms
Zig

Example: Crypt2.GetSignedAttributes method

Demonstrates how to call the GetSignedAttributes method.

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();

    const bd_pkcs7 = try chilkat.BinData.init();
    defer bd_pkcs7.deinit();
    bd_pkcs7.loadFile("qa_data/cades/CAdES-T/Signature-C-T-1.p7m") catch {
        std.debug.print("{s}\n", .{try bd_pkcs7.getLastErrorText(alloc)});
        return;
    };

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.setEmitCompact(false);

    const sb_json = try chilkat.StringBuilder.init();
    defer sb_json.deinit();
    var i: i32 = 0;
    var try_next: bool = true;
    while (try_next) {
        if (crypt.getSignedAttributes(i, bd_pkcs7, sb_json)) {
            json.loadSb(sb_json) catch {};
            std.debug.print("{d}: \n", .{i});
            std.debug.print("{s}\n", .{try json.emit(alloc)});
        } else {
            try_next = false;
        }

        i = i + 1;
    }

    // Sample output:

    // 0:
    // {
    //   "signedAttributes": [
    //     {
    //       "oid": "1.2.840.113549.1.9.3",
    //       "name": "Content Type"
    //     },
    //     {
    //       "oid": "1.2.840.113549.1.9.5",
    //       "name": "Signing Time"
    //     },
    //     {
    //       "oid": "1.2.840.113549.1.9.4",
    //       "name": "Message Digest"
    //     },
    //     {
    //       "oid": "1.2.840.113549.1.9.16.2.47",
    //       "name": "Signing Certificate V2"
    //     }
    //   ]
    // }
}