Zig Requires Chilkat v10.1.2+
Zig
Apple Keychain - List Certificates
See more Apple Keychain Examples
Iterates over the certificates in the Apple Keychain.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();
// On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
// The argument passed to OpenCurrentUserStore is ignored.
cert_store.openCurrentUserStore(false) catch {
std.debug.print("{s}\n", .{try cert_store.getLastErrorText(alloc)});
return;
};
const num_certs = cert_store.getNumCertificates();
std.debug.print("numCerts = {d}\n", .{num_certs});
const cert = try chilkat.Cert.init();
defer cert.deinit();
var i: i32 = 0;
while (i < num_certs) {
cert_store.getCert(i, cert) catch {};
std.debug.print("{s}\n", .{try cert.getSubjectDN(alloc)});
std.debug.print("{s}\n", .{try cert.getSubjectCN(alloc)});
std.debug.print("{s}\n", .{try cert.getSerialNumber(alloc)});
std.debug.print("----\n", .{});
i = i + 1;
}
cert_store.closeCertStore() catch {};
}