Skip to content

Software License Dongle for Nim

Nim binds with importc, which is part of the language, and resolves the library at run time through dynlib — so there are no dependencies and nothing to link. If you chose Nim to ship a small self-contained native binary, the licensing does not change that.

Nimble version badge

nimble install keynub_licdongleCode language: Bash (bash)

Reading a License

import keynub_licdongle

let ctx = newContext()
defer: ctx.close()

let dongle = ctx.open()                     # first dongle, or ctx.open("serial")
discard dongle.verifyGenuine()              # raises unless genuine
defer: dongle.close()

let session = dongle.openSession()
defer: session.close()
let license = session.readRecord("license")Code language: Nim (formerly Nimrod) (nimrod)

defer does the work that a destructor does elsewhere: each resource is released when its scope ends, including when an exception unwinds, and the cleanup sits next to the acquisition where you can see it is there.

The Library Name Is a Compile-Time Define

Which library the binding loads is set with -d:keynubLib=..., so a build can name the library explicitly when it is not on the default search path:

nim c -d:keynubLib=keynub_licdongle -r tests/my_licence_test.nim
nim c -d:release myapp.nimCode language: Bash (bash)

Pointed at a stand-in library, your own test suite can exercise the licensing path in CI with no dongle attached, as the binding’s tests/test_standin.nim does, and there is no code path in the release build that exists only for testing.

The rule that holds in every language: do not branch on a boolean. Encrypt data your program needs with appEncrypt when you build the product, decrypt it through the dongle at run time, and removing the check leaves the program with nothing to compute rather than a working unlicensed copy.

Shipping the Native Library with a Nim Application

The keynub_licdongle Nimble package declares the core library’s functions with importc over dynlib, so the library is loaded by name when the program starts; the name is a compile-time define, so a program can pin a specific file. Ship keynub_licdongle for the platform next to the executable or on the search path.

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 Nim Developers Ask

Which Nim Versions Does the Binding Support?

Nim 1.6 and later, including Nim 2, on Windows, Linux and macOS, with no dependencies.

Does a Nim 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 Nim 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.

Who Can Read the License Records on a Dongle?

Anyone holding the dongle: a program opens a session and reads records, and can decrypt data sealed for that dongle. Writing records, erasing them and incrementing counters need your write key. What the dongle guarantees is that none of it is available without the dongle present.

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 Nim 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: nim/verify_and_read.nim. Binding source: bindings/nim. 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