Zig
Zig
Load P7B and Iterate Certificates
See more PEM Examples
Demonstrates how to load a .p7b containing one or more certificates access each of them.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
success = false;
// The Chilkat PEM class was introduced in v9.5.0.49.
// It requires the bundle to be unlocked, as shown above.
const pem = try chilkat.Pem.init();
defer pem.deinit();
// Load the .p7b from a file.
pem.loadP7bFile("../myCertFiles/myP7b.p7b") catch {
std.debug.print("{s}\n", .{try pem.getLastErrorText(alloc)});
return;
};
// Note: If the app already has the p7b loaded in memory, the LoadP7b method
// may be called instead. (see the online reference documentation)
// Iterate over the certificates.
const num_certs = pem.getNumCerts();
var i: i32 = 0;
while (i < num_certs) {
ERROR: Method not in the Zig package: Pem.GetCert
ERROR: Method not in the Zig package: Pem.GetCert
const cert = pem.ERROR();
std.debug.print("Certificate {d} : {s}\n", .{ i, try cert.getSubjectDN(alloc) });
i = i + 1;
}
}