Skip to content

Software License Dongle for Zig

Every other binding on this site re-declares the C API in its own language, and every one of those declarations is a thing that can quietly fall out of step with the ABI. The SDK guards against that with tests. Zig does not need them: @cImport compiles the real licdongle.h, so a changed prototype is a compile error in your build rather than a wrong call at run time.

Reading a license

const keynub = @import(“keynub_licdongle”); var ctx = try keynub.Context.init(); defer ctx.deinit(); var dongle = try ctx.open(null); // null = first dongle found defer dongle.close(); _ = try dongle.verifyGenuine(); // errors unless genuine var session = try dongle.openSession(); defer session.close(); const license = try session.readRecord(allocator, “license”); defer allocator.free(license);

Allocation is explicit, as everywhere in Zig: the calls that return variable-length data take an allocator and you free the result. Nothing is allocated behind your back, which matters if you are using Zig precisely because you want to know where the memory went.

Do not gate on a boolean

// Weak — one branch to remove. if (!dongle.isGenuine()) return error.Unlicensed; // Strong — the data your program needs only exists with the dongle present. const coefficients = try session.appDecrypt(allocator, blob_from_your_installer);

Zig produces a native binary, which is a harder target than a managed assembly — but a single if is still a single conditional jump, and the people who do this for a living find those quickly. Put the dongle on the critical path and the question stops being how well your check is hidden.

Code

Runnable sample: zig/verify_and_read.zig. Binding source: bindings/zig. Both are Apache-2.0, in the public SDK repository; the prebuilt native libraries are in the repository’s natives/ folder, one per platform.

All supported languages · All industries · Buy a KeyNub · Ask us something