Skip to main content

Crate rustify_licensing

Crate rustify_licensing 

Source
Expand description

§rustify-licensing

Framework-agnostic in-app licensing for native Rust desktop apps: validate a key, node-lock the machine, cache the result, and stay unlocked through a bounded offline grace window — failing closed on an authoritative denial.

A framework-agnostic core plus thin adapters, so the same logic drives a Bevy app, a headless CLI, an egui/immediate-mode GUI, or tests.

§Shape

  • core — pure, runtime-agnostic: LicenseState persistence + fingerprint, LicenseStatus, CheckErr (the load-bearing Denied vs Offline split), and the core::engine that folds a check result into a status.
  • provider — the LicenseProvider trait and the KeygenProvider impl (the exact Keygen validate/activate/node-lock dance). Swap in Polar later.
  • adapters — headless (a blocking driver) and, behind the bevy feature, a [adapters::bevy] plugin with resources, systems, and an event API.

§Quick start (headless)

use rustify_licensing::{KeygenProvider, LicenseConfig, LicenseState, StorageConfig};
use rustify_licensing::adapters::headless::check_blocking;

let config = LicenseConfig {
    account_id: "your-keygen-account-uuid".into(),
    api_base: "https://api.keygen.sh/v1".into(),
    grace_secs: 14 * 24 * 60 * 60,
    storage: StorageConfig::app_data("MyApp", "license.env", None, Some("MYAPP_LICENSE_KEY")),
    buy_url: "https://myapp.example/#pricing".into(),
};
let provider = KeygenProvider::from_config(&config);
let mut state = LicenseState::load(&config.storage);
let status = check_blocking(&config, &provider, &mut state, |line| println!("… {line}"));
println!("status: {status:?}");

Re-exports§

pub use crate::core::config::LicenseConfig;
pub use crate::core::config::StorageConfig;
pub use crate::core::error::CheckErr;
pub use crate::core::state::now_secs;
pub use crate::core::state::LicenseState;
pub use crate::core::status::LicenseStatus;
pub use crate::provider::KeygenProvider;
pub use crate::provider::LicenseProvider;
pub use crate::adapters::worker::LicenseWorker;

Modules§

adapters
Thin glue between the pure crate::core and a host runtime. headless is always available; the Bevy plugin is behind the bevy feature so the core builds without it.
core
Framework-agnostic licensing core: no Bevy, no async runtime, no UI. Everything here is plain data + pure functions, so it’s trivially testable and portable.
provider
The pluggable licensing backend. Keygen today; the trait keeps Polar (MoR + licensing in one) or an offline Ed25519-signed-key verifier a later drop-in without touching the core engine.

Functions§

open_url
Open a URL in the user’s default browser (for a “Buy” button → config.buy_url).