Zig
Zig
Find Certificate by Subject O (Organization)
See more Cert Store Examples
Demonstrates how to find a certificate having the specified subject organization.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;
};
// Find the certificate having a Subject O = "ICP-Brasil".
const json = try chilkat.JsonObject.init();
defer json.deinit();
const organization = "ICP-Brasil";
json.updateString("O", organization) catch {};
const cert = try chilkat.Cert.init();
defer cert.deinit();
if (cert_store.findCert(json, cert)) {
// Show the full distinguished name of the certificate.
std.debug.print("Found: {s}\n", .{try cert.getSubjectDN(alloc)});
} else |_| {
std.debug.print("Not found.\n", .{});
}
}