mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-10 10:30:30 +08:00
feat(rust): add Provider trait + refactor C ABI to route through Provider
SelfHostedProvider implements Provider trait for offline license verification
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
use std::collections::HashMap;
|
||||
use crate::{CraftContext, LicenseInfo, error::LicenseError};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LicenseStatus {
|
||||
pub licensed: bool,
|
||||
pub not_after: Option<i64>,
|
||||
pub features: HashMap<String, bool>,
|
||||
pub device_count: u32,
|
||||
pub max_devices: u32,
|
||||
pub heartbeat_due: Option<i64>,
|
||||
}
|
||||
|
||||
pub struct ActivateResponse {
|
||||
pub success: bool,
|
||||
pub device_id: String,
|
||||
pub license_payload: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct HeartbeatResponse {
|
||||
pub valid: bool,
|
||||
pub lease_until: Option<i64>,
|
||||
pub update_available: bool,
|
||||
pub new_license_payload: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
pub trait Provider: Send + Sync {
|
||||
fn initialize(&mut self, ctx: &CraftContext, config_json: &str) -> Result<(), LicenseError>;
|
||||
fn activate(&self, ctx: &CraftContext, license_key: &str) -> Result<ActivateResponse, LicenseError>;
|
||||
fn check_license(&self, ctx: &CraftContext) -> Result<LicenseStatus, LicenseError>;
|
||||
fn heartbeat(&self, ctx: &CraftContext) -> Result<HeartbeatResponse, LicenseError>;
|
||||
fn has_feature(&self, ctx: &CraftContext, name: &str) -> bool;
|
||||
fn release(&mut self) -> Result<(), LicenseError>;
|
||||
fn get_license_info(&self, ctx: &CraftContext) -> LicenseInfo;
|
||||
fn close(&mut self);
|
||||
}
|
||||
Reference in New Issue
Block a user