Zig
Zig
Find Certificate by Serial Number
See more Cert Store Examples
Demonstrates how to find a certificate having the specified hexadecimal serial number.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 example will search the certs on connected USB tokens and smartcards.
const arg_not_used = "";
cert_store.openSmartcard(arg_not_used) catch {
std.debug.print("{s}\n", .{try cert_store.getLastErrorText(alloc)});
return;
};
// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
const hex_serial = "48FC93B46055948D36A7C98A89D69416";
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("serial", hex_serial) catch {};
const cert = try chilkat.Cert.init();
defer cert.deinit();
if (cert_store.findCert(json, cert)) {
// Show the serial number and subject CN
std.debug.print("Found: {s}, {s}\n", .{ try cert.getSerialNumber(alloc), try cert.getSubjectCN(alloc) });
} else |_| {
std.debug.print("Not found.\n", .{});
}
}