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);Code language: JavaScript (javascript)
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.
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);Code language: JavaScript (javascript)
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.
Shipping the Native Library with a Zig Application
The Zig binding compiles the real header through @cImport, so it cannot drift from the C API, and links the prebuilt library for the target from natives/; the repository is a Zig package (build.zig.zon) that zig fetch takes by URL. Link the shared library and ship it next to the executable or on the search path, or link the static library for a self-contained binary.
The prebuilt libraries for every platform are in the SDK repository’s natives/<platform>/ folder, with a SHA-256 manifest: Windows x64, x86 and ARM64, Linux x86_64 and aarch64, and universal macOS binaries for Intel and Apple silicon. On Linux, install the udev rule from NATIVES.md once, so that ordinary users may open the device.
Questions Zig Developers Ask
Which Zig Versions Does the Binding Support?
Zig 0.14.0 and later, as declared in build.zig.zon, on Windows, Linux and macOS.
Can Zig Cross-Compile a Program That Uses the Dongle?
For the platforms the SDK ships libraries for, yes: point the build at the target’s natives/<platform>/ folder and Zig links it; the static library gives one file to ship.
Does a Zig Application Need Administrator Rights to Talk to the Dongle?
No, and no driver either: the dongle is a USB HID device that the operating systems handle with their built-in class drivers. On Linux, install the shipped udev rule once so that ordinary users may open it; without the rule the SDK reports access denied and names the cause in its error detail.
Does a Zig License Check Need an Internet Connection?
No. Verification is a local exchange between your program and the dongle over USB: the SDK checks the dongle’s certificate chain to KeyNub’s root and runs a live challenge-response. There is no activation server and no account, so the check works on air-gapped machines.
Does It Run on ARM: Windows on ARM, Apple Silicon, aarch64 Linux?
Yes. The SDK ships native libraries for Windows x64, x86 and ARM64, Linux x86_64 and aarch64, and universal macOS binaries for Intel and Apple silicon.
Can a License Written from Zig Be Read by a Program in Another Language?
Yes. Every binding drives the same core library and the same dongle, and records and sealed data are language-neutral bytes. Your issuing tool can be written in one language and your product in another.
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