Crates.io | license-system |
lib.rs | license-system |
version | |
source | src |
created_at | 2025-03-14 03:15:55.494653+00 |
updated_at | 2025-03-14 06:35:05.105545+00 |
description | 授权协议框架 |
homepage | https://gitee.com/eternalnight996 |
repository | |
max_upload_size | |
id | 1591764 |
Cargo.toml error: | TOML parse error at line 26, column 1 | 26 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Authorization System
Module | Status | Progress | Remarks |
---|---|---|---|
ChaCha20 Encryption | ✅ | 100% | Integrated Libsodium |
AES-256-GCM Encryption | 🔄 | 100% | Final testing in progress |
Offline Authorization | ✅ | 100% | Hardware binding supported |
Online Verification | 🔄 | 30% | Developing distributed auth |
License Generation | ✅ | 100% | Supports RSA/ECC algorithms |
license-system = { version = "0.1", default-features = false, features = ["chacha20","aes256gcm"] }
use std::sync::Arc;
use license_system::{
LicenseGenerator as _, LicenseManager, LicenseValidator as _, ChaCha20Protocol,
};
fn main() -> e_utils::Result<()> {
// 创建授权管理器(使用固定密钥便于测试)
let secret_key: [u8; 32] = [
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x13, 0x24, 0x35, 0x46, 0x57, 0x68,
0x79, 0x8a,
];
let protocol = Arc::new(ChaCha20Protocol::new(secret_key));
let license_manager = LicenseManager::new(protocol, 8)?;
// Test users
let user_ids = vec![
"user1",
"user2",
"user3",
];
println!("生成批量授权...");
let licenses = license_manager.generate_batch_licenses(user_ids, 2)?;
for license in &licenses {
println!(
"用户: {}, 授权码: {}, 过期时间: {}",
license.user_id, license.license_key, license.expire_time
);
}
// test
println!("\n批量验证授权...");
let verify_results = license_manager.verify_batch_licenses(&licenses)?;
for result in &verify_results {
println!("用户 {}: {}", result.user_id, result.message);
}
// test
println!("\n验证单个授权...");
if let Some(first_license) = licenses.first() {
match license_manager.verify_license(&first_license.license_key) {
Ok(res) => println!("验证结果: {} 剩余{}小时", res.message, res.days_remaining),
Err(e) => println!("验证失败: {}", e),
}
}
Ok(())
}
We welcome all types of contributions!
Before submitting PRs, please ensure:
Dual-licensed under MIT and Apache 2.0.