mirror of
https://github.com/luxfi/license.git
synced 2026-10-30 16:21:14 +00:00
- Stdlib-only deterministic binary token format (no JWT / CBOR dep). - Go API: VerifyToken, LoadFromEnv, HasFeature, HasFeatureOrDie. - Stable C ABI + C++17 RAII wrapper for non-Go commercial binaries (luxcpp/cevm). - cmd/lux-license: keygen / issue / inspect / verify. - Embedded development key; warns once at runtime until production key swap. - 22 Go tests + 1 cgo round-trip test, all passing.
86 lines
2.9 KiB
C
86 lines
2.9 KiB
C
/*
|
|
* Copyright (C) 2020-2026, Lux Industries Inc. All rights reserved.
|
|
* See the file LICENSE for licensing terms.
|
|
*
|
|
* lux_license.h — C ABI for runtime verification of Lux commercial license
|
|
* tokens. Mirrors github.com/luxfi/license (Go).
|
|
*
|
|
* Build the shared library:
|
|
* cd capi && go build -buildmode=c-shared -o liblux_license.so .
|
|
* Or static archive:
|
|
* cd capi && go build -buildmode=c-archive -o liblux_license.a .
|
|
*
|
|
* The library never touches a private key. Token issuance is exclusively
|
|
* Go-side (cmd/lux-license).
|
|
*/
|
|
|
|
#ifndef LUX_LICENSE_H
|
|
#define LUX_LICENSE_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Opaque handle to a verified Claims set. Free with lux_license_free. */
|
|
typedef struct LuxLicenseClaims LuxLicenseClaims;
|
|
|
|
/*
|
|
* lux_license_load_from_env discovers and verifies a license token from the
|
|
* environment (LUX_LICENSE, LUX_LICENSE_FILE, then $HOME/.lux/license.jwt).
|
|
* Returns NULL on failure; call lux_license_last_error for a thread-local
|
|
* error message.
|
|
*/
|
|
LuxLicenseClaims* lux_license_load_from_env(void);
|
|
|
|
/*
|
|
* lux_license_verify_base64 verifies a base64-encoded token. The caller owns
|
|
* the input string (NUL-terminated). Returns NULL on failure.
|
|
*/
|
|
LuxLicenseClaims* lux_license_verify_base64(const char* token_b64);
|
|
|
|
/* lux_license_free releases an opaque claims handle. NULL is a no-op. */
|
|
void lux_license_free(LuxLicenseClaims* c);
|
|
|
|
/* lux_license_has_feature returns 1 if scope is authorized, 0 otherwise. */
|
|
int lux_license_has_feature(const LuxLicenseClaims* c, const char* scope);
|
|
|
|
/*
|
|
* lux_license_customer_id / lux_license_license_id return pointers into the
|
|
* claims struct that remain valid until lux_license_free is called.
|
|
*/
|
|
const char* lux_license_customer_id(const LuxLicenseClaims* c);
|
|
const char* lux_license_license_id(const LuxLicenseClaims* c);
|
|
|
|
/* Returns the number of scopes and the i-th scope pointer (or NULL OOB). */
|
|
int lux_license_scope_count(const LuxLicenseClaims* c);
|
|
const char* lux_license_scope(const LuxLicenseClaims* c, int i);
|
|
|
|
/* Unix timestamps; returns 0 if the field is unset (e.g. no expiry). */
|
|
int64_t lux_license_issued_at_unix(const LuxLicenseClaims* c);
|
|
int64_t lux_license_expiry_unix(const LuxLicenseClaims* c);
|
|
|
|
/*
|
|
* lux_license_require_feature_or_die loads the license from the environment,
|
|
* verifies it covers `scope`, and aborts the process (exit 1) with a clear
|
|
* stderr message if anything is missing. Intended for use at process start
|
|
* in commercial-only binaries.
|
|
*/
|
|
void lux_license_require_feature_or_die(const char* scope);
|
|
|
|
/*
|
|
* lux_license_last_error returns a NUL-terminated, thread-local error string
|
|
* describing the failure of the most recent lux_license_* call on this
|
|
* thread. The pointer is valid until the next lux_license_* call on this
|
|
* thread. Returns "" if no error.
|
|
*/
|
|
const char* lux_license_last_error(void);
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* LUX_LICENSE_H */
|