Skip to content

Software License Dongle for Rust

The Rust binding is a safe wrapper over the same C ABI, with the unsafe FFI surface kept in one place rather than spread through your code.

crates.io version badge

cargo add keynub-licdongleCode language: Bash (bash)
use keynub_licdongle::Context;

let ctx = Context::new()?;
let dongle = ctx.open(None)?;            // first dongle, or Some("serial")
dongle.verify_genuine()?;                // errors unless genuine

let session = dongle.open_session()?;
let license: Vec<u8> = session.read_record("license")?;
// Drop closes the session, then the dongle, then the context.Code language: Rust (rust)

Fallible calls return Result, so the error paths are the ones the compiler already makes you handle, and Drop closes the device without a cleanup path to forget.

One deliberate exception to the Result pattern

is_genuine returns a plain bool rather than Result<bool>: a licence gate should fail closed when no dongle is present, not force you to decide what an error means at every call site.

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

No dependencies beyond std

The crate pulls in nothing but the standard library. A licensing crate is the last place you want a transitive dependency tree: each crate in it is another maintainer who can publish a release that changes what your check does, and another item for whoever signs off your build.

Lifetimes also carry weight here that the other bindings have to enforce at run time. A session borrows the dongle it came from and a dongle borrows its context, so the destructor ordering that would let a session outlive its device is not a bug you can write – it does not compile.

Code

Runnable sample: rust/verify_and_read. Binding source: bindings/rust. 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