| Crates.io | alvan-lic |
| lib.rs | alvan-lic |
| version | 0.1.0 |
| created_at | 2025-05-31 10:52:13.167596+00 |
| updated_at | 2025-05-31 10:52:13.167596+00 |
| description | A Rust crate for generating and validating time-based license keys with offline validation |
| homepage | |
| repository | https://github.com/WebChatAppAi/alvan-lic |
| max_upload_size | |
| id | 1696273 |
| size | 94,034 |
A Rust crate for generating and validating time-based license keys with offline validation.
Add this to your Cargo.toml:
[dependencies]
alvan-lic = "0.1.0"
Or install the CLI tool directly:
cargo install alvan-lic
Then run the interactive CLI:
alvan-cli
use alvan_lic::{LicenseGenerator, LicenseValidator};
fn main() {
// Use a strong secret key in production
let secret_key = "your-super-secret-key";
// Generate a license valid for 24 hours
let generator = LicenseGenerator::new(secret_key);
let license_key = generator.generate_key(24).unwrap();
println!("License: {}", license_key);
// Validate the license
let validator = LicenseValidator::new(secret_key);
match validator.validate_key(&license_key) {
Ok(info) => {
println!("Valid for {:.1} more hours", info.hours_remaining);
}
Err(e) => {
println!("Invalid license: {}", e);
}
}
}
use alvan_lic::LicenseGenerator;
let generator = LicenseGenerator::new("secret-key");
// Generate different duration licenses
let one_hour = generator.generate_key(1).unwrap();
let one_day = generator.generate_key(24).unwrap();
let one_month = generator.generate_key(24 * 30).unwrap();
let one_year = generator.generate_key(24 * 365).unwrap();
use alvan_lic::LicenseValidator;
let validator = LicenseValidator::new("secret-key");
match validator.validate_key(&license_key) {
Ok(info) => {
println!("License is valid!");
println!("Issued: {}", info.issued_at);
println!("Expires: {}", info.expires_at);
println!("Hours remaining: {:.2}", info.hours_remaining);
}
Err(e) => {
println!("License validation failed: {}", e);
}
}
Secret Key:
Offline Validation:
Time Synchronization:
All license keys start with alvan- followed by a base64-encoded payload and signature.
Example: alvan-MTcwNDQ2NzI4MjoxNzA0NTUzNjgyLkPCt8K3w4Qpw6ZVwq0N...
The crate provides detailed error types:
InvalidFormat: The license key format is incorrectInvalidSignature: The signature doesn't match (wrong secret key)Expired: The license has expiredInvalidData: The license data is corruptedSee the examples/ directory for more detailed usage examples.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under either of
at your option.