Skip to content
LICENTIVO / INTEGRATION

Rust Software Licensing: Activation & Feature Checks

Add the Rust crate to a Cargo application and protect a real export with a typed callback. The native core manages signed grants, device credentials, heartbeats and floating seats.

Rust 1.77+Updated

1. Prepare the product and license

Start with a node-locked license and an ordinary export feature. Add metered usage only after the basic authorization flow works.

Device quota counts current activations and is returned on release. Ordinary licenses remain counted while offline; floating licenses also return quota when their leases expire.

  1. Copy the Product ID from Console > Products. Open that product’s Signing public keys and paste every key ID/public key pair into the initialization code, replacing YOUR_PRODUCT_ID, YOUR_KEY_ID and YOUR_PUBLIC_KEY. Quick integration can generate these public code constants. No product configuration file is required; the SDK defaults to https://www.licentivo.com.
  2. In Quick integration, create or select a product. Enable a feature named export in its policy and prepare a test license.

2. Install the SDK

Run the command below in your application project, or add the build dependency, to install SDK 0.11.6. The package manager retrieves the SDK; no source ZIP, manual extraction or local source path is required.

Native build errors usually indicate missing C11 or libcurl headers, mismatched architectures or the wrong Windows target. The current Windows native core requires GNU/MinGW; MSVC acceptance is pending.

Terminal · new Cargo application
cargo new licensed_app
cd licensed_app
cargo add licentivo@=0.11.6
Ubuntu / Debian · native dependencies
sudo apt-get update
sudo apt-get install build-essential libcurl4-openssl-dev libssl-dev pkg-config
Windows x64 · PowerShell · GNU/MinGW
rustup toolchain install stable-x86_64-pc-windows-gnu --profile minimal
$env:LICENTIVO_CURL_ROOT = "C:/path/to/curl-mingw"
$env:PATH = "$env:LICENTIVO_CURL_ROOT/bin;$env:PATH"
cargo +stable-x86_64-pc-windows-gnu build

3. Protect a real export

Move SDK startup into your application’s startup or activation handler. Read the customer key from your activation form, pass your own product ID and trusted keys, and keep the client alive until shutdown. Put run_feature at the actual business entry point; replace the report writer with your own operation.

Rust 1.77+ · src/main.rs
use licentivo::{Client, Error};
use std::{env, fs};

// BEGIN LICENTIVO PRODUCT
// Copy Product ID and all key ID/public key pairs from Console > Products > Signing public keys.
const PRODUCT_ID: &str = "YOUR_PRODUCT_ID";
const TRUSTED_KEYS_JSON: &str = r#"{"YOUR_KEY_ID":"YOUR_PUBLIC_KEY"}"#;
// END LICENTIVO PRODUCT

fn setting(name: &str, fallback: &str) -> String {
    env::var(name).ok().filter(|value| !value.is_empty()).unwrap_or_else(|| fallback.into())
}

fn export_report(path: &str) -> Result<(), Error> {
    // Replace this write with your existing export operation.
    fs::write(path, "A report generated by the licensed application.\n")?;
    Ok(())
}

fn run() -> Result<(), Error> {
    // A GUI supplies the activation input. Later starts use an empty key.
    let mut client = Client::open_product(
        PRODUCT_ID, TRUSTED_KEYS_JSON,
        &setting("LICENTIVO_LICENSE_KEY", ""),
    )?;
    let feature = setting("LICENTIVO_FEATURE", "export");
    let path = setting("LICENTIVO_OUTPUT", "licensed-report.txt");
    if setting("LICENTIVO_METERED", "0") == "1" {
        client.run_metered_feature(&feature, 1, &setting("LICENTIVO_OPERATION_ID", ""), || export_report(&path))?;
    } else {
        client.run_feature(&feature, || export_report(&path))?;
    }
    println!("License OK: {feature} is available\nExport completed: {path}");
    // Real app: keep client alive until shutdown. Drop returns floating seats;
    // do not deactivate a device on a normal application exit.
    Ok(())
}

fn main() {
    if let Err(error) = run() { eprintln!("{error}"); std::process::exit(2); }
}

4. Keep the client alive until shutdown

This command-line example performs one operation and exits. In a desktop application, open one client at startup, invoke the feature callback from the export action, and close the client only when the application exits.

After activation, later starts can leave LICENTIVO_LICENSE_KEY empty and restore the private credential under the same user and cache location. Keep that credential in the user application-data directory. Closing stops heartbeats and returns floating seats; normal exit should not deactivate a node-locked device.

Offline access is available only when the policy permits it and the signed grant remains valid. An expired or denied feature must remain blocked. Metered operations require a network connection.

Keep the mutable Client in the owning application state. It is Send but not Sync: move it to one worker rather than sharing concurrent calls. Drop stops background work and returns floating seats. Close consumes the client; normal exit preserves device binding.

5. Run and verify the result

Copy the Product ID from Console > Products. Open that product’s Signing public keys and paste every key ID/public key pair into the initialization code, replacing YOUR_PRODUCT_ID, YOUR_KEY_ID and YOUR_PUBLIC_KEY. Quick integration can generate these public code constants. No product configuration file is required; the SDK defaults to https://www.licentivo.com.

  1. Confirm that a valid license with export access creates licensed-report.txt.
  2. Clear LICENTIVO_LICENSE_KEY and run again using the same user account: the saved credential should restore.
  3. Set LICENTIVO_FEATURE to a feature absent from the license and LICENTIVO_OUTPUT to a fresh filename. The program must report a denial without creating that file.
  4. Test an offline restart only with a permitted, unexpired signed grant. Do not bypass a failed feature check after a background refresh error.
Windows · PowerShell
$env:LICENTIVO_LICENSE_KEY = 'YOUR_LICENSE_KEY'
cargo +stable-x86_64-pc-windows-gnu run
Linux · Bash
LICENTIVO_LICENSE_KEY=YOUR_LICENSE_KEY cargo run

Common integration problems

Check the product ID, every key ID/public key pair and the customer’s license input. Public verification keys belong to a product; customer licenses and saved device credentials are separate. Do not distribute development test keys or vendor management API keys.

Feature denied, device limit reached or license expired: inspect the license and policy in the console, then show the SDK error to the customer. A failed authorization must not call the export function.

run_feature checks feature access; the metered variant reserves and settles configured usage. Use a stable operation ID per real business job and inspect its durable result before recovering an interrupted job.

Native build errors usually indicate missing C11 or libcurl headers, mismatched architectures or the wrong Windows target. The current Windows native core requires GNU/MinGW; MSVC acceptance is pending.