Zig
Zig
Iterate over Certificates in a Certificate Store
See more Cert Store Examples
Demonstrates how to iterate over the certificates in a certificate store.Note: Requires Chilkat v10.1.2 or later.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const cert_store = try chilkat.CertStore.init();
defer cert_store.deinit();
// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
const read_only = false;
cert_store.openCurrentUserStore(read_only) catch {
std.debug.print("{s}\n", .{try cert_store.getLastErrorText(alloc)});
return;
};
const cert = try chilkat.Cert.init();
defer cert.deinit();
const num_certs = cert_store.getNumCertificates();
var i: i32 = 0;
while (i < num_certs) {
// Load the cert object with the Nth certificate.
cert_store.getCert(i, cert) catch {};
std.debug.print("{d}: {s}\n", .{ i, try cert.getSubjectCN(alloc) });
i = i + 1;
}
}