Zig
Zig
Convert CRL PEM to XML
See more PEM Examples
Loads a CRL (Certificate Revocation List) from the PEM file format and converts to XML to allow for visual examination and parsing.Note: This example requires Chilkat v9.5.0.77 or greater.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// This example requires Chilkat v9.5.0.77 or greater.
const pem = try chilkat.Pem.init();
defer pem.deinit();
pem.setVerboseLogging(true);
pem.loadPemFile("qa_data/crl/sampleCrl.pem", "password_not_used") catch {
std.debug.print("{s}\n", .{try pem.getLastErrorText(alloc)});
return;
};
const num_crls = pem.getNumCrls();
var i: i32 = 0;
const asn = try chilkat.Asn.init();
defer asn.deinit();
const xml = try chilkat.Xml.init();
defer xml.deinit();
while (i < num_crls) {
// Get the CRL as base64 (multi-line)
const crl_base64 = pem.getEncodedItem(alloc, "crl", "", "base64_mime", i) catch {
std.debug.print("{s}\n", .{try pem.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{crl_base64});
asn.loadEncoded(crl_base64, "base64") catch {
std.debug.print("{s}\n", .{try asn.getLastErrorText(alloc)});
return;
};
// Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
xml.loadXml(try asn.asnToXml(alloc)) catch {};
std.debug.print("{s}\n", .{try xml.getXml(alloc)});
// Use this online tool to generate parsing code from CRL XML:
// Generate Parsing Code from XML
std.debug.print("-------------------------------------\n", .{});
i = i + 1;
}
}