pub struct LicensePayload {
pub format_version: u32,
pub license_id: String,
pub customer_id: String,
pub customer_name: Option<String>,
pub issued_at: DateTime<Utc>,
pub constraints: LicenseConstraints,
pub metadata: Option<HashMap<String, Value>>,
}Expand description
The core license payload containing all license information.
This structure holds all the data that defines a license, including identification, temporal constraints, and feature restrictions. It is serialized to JSON and then signed by the publisher.
§Security Note
The payload itself is not encrypted, only signed. Anyone with access to the license file can read its contents. Do not store secrets in the license payload.
Fields§
§format_version: u32Version of the license format for forward compatibility. This allows the library to reject incompatible future formats.
license_id: StringUnique identifier for this specific license. Should be a UUID or similar unique identifier.
customer_id: StringIdentifier for the customer or organization this license is issued to.
customer_name: Option<String>Human-readable name of the customer or organization.
issued_at: DateTime<Utc>Timestamp when this license was issued.
constraints: LicenseConstraintsAll constraints and restrictions applied to this license.
metadata: Option<HashMap<String, Value>>Optional additional metadata as key-value pairs. Useful for application-specific data that doesn’t fit standard fields.
Implementations§
Source§impl LicensePayload
impl LicensePayload
Sourcepub fn is_version_supported(&self) -> bool
pub fn is_version_supported(&self) -> bool
Checks if the license format version is supported by this library.
Sourcepub fn get_value(&self, key: &str) -> Option<&Value>
pub fn get_value(&self, key: &str) -> Option<&Value>
Gets a custom value from the license metadata by key.
Returns None if the key doesn’t exist or if no metadata is present.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// if let Some(value) = payload.get_value("max_users") {
// println!("Max users: {}", value);
// }Sourcepub fn get_value_or<'a>(&'a self, key: &str, default: &'a Value) -> &'a Value
pub fn get_value_or<'a>(&'a self, key: &str, default: &'a Value) -> &'a Value
Gets a custom value from the license metadata, or returns a default value.
§Example
use rust_license_key::prelude::*;
use serde_json::json;
// After validating a license:
// let max_users = payload.get_value_or("max_users", &json!(10));Sourcepub fn get_string(&self, key: &str) -> Option<&str>
pub fn get_string(&self, key: &str) -> Option<&str>
Gets a string value from the license metadata.
Returns None if the key doesn’t exist or the value is not a string.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// if let Some(tier) = payload.get_string("tier") {
// println!("License tier: {}", tier);
// }Sourcepub fn get_string_or<'a>(&'a self, key: &str, default: &'a str) -> &'a str
pub fn get_string_or<'a>(&'a self, key: &str, default: &'a str) -> &'a str
Gets a string value from the license metadata, or returns a default.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// let tier = payload.get_string_or("tier", "basic");Sourcepub fn get_i64(&self, key: &str) -> Option<i64>
pub fn get_i64(&self, key: &str) -> Option<i64>
Gets an i64 value from the license metadata.
Returns None if the key doesn’t exist or the value is not a number.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// if let Some(max_users) = payload.get_i64("max_users") {
// println!("Max users: {}", max_users);
// }Sourcepub fn get_i64_or(&self, key: &str, default: i64) -> i64
pub fn get_i64_or(&self, key: &str, default: i64) -> i64
Gets an i64 value from the license metadata, or returns a default.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// let max_users = payload.get_i64_or("max_users", 10);Sourcepub fn get_u64(&self, key: &str) -> Option<u64>
pub fn get_u64(&self, key: &str) -> Option<u64>
Gets a u64 value from the license metadata.
Returns None if the key doesn’t exist or the value is not a positive number.
Sourcepub fn get_u64_or(&self, key: &str, default: u64) -> u64
pub fn get_u64_or(&self, key: &str, default: u64) -> u64
Gets a u64 value from the license metadata, or returns a default.
Sourcepub fn get_f64(&self, key: &str) -> Option<f64>
pub fn get_f64(&self, key: &str) -> Option<f64>
Gets an f64 value from the license metadata.
Returns None if the key doesn’t exist or the value is not a number.
Sourcepub fn get_f64_or(&self, key: &str, default: f64) -> f64
pub fn get_f64_or(&self, key: &str, default: f64) -> f64
Gets an f64 value from the license metadata, or returns a default.
Sourcepub fn get_bool(&self, key: &str) -> Option<bool>
pub fn get_bool(&self, key: &str) -> Option<bool>
Gets a boolean value from the license metadata.
Returns None if the key doesn’t exist or the value is not a boolean.
Sourcepub fn get_bool_or(&self, key: &str, default: bool) -> bool
pub fn get_bool_or(&self, key: &str, default: bool) -> bool
Gets a boolean value from the license metadata, or returns a default.
Sourcepub fn get_array(&self, key: &str) -> Option<&Vec<Value>>
pub fn get_array(&self, key: &str) -> Option<&Vec<Value>>
Gets an array value from the license metadata.
Returns None if the key doesn’t exist or the value is not an array.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// if let Some(modules) = payload.get_array("allowed_modules") {
// for module in modules {
// println!("Module: {}", module);
// }
// }Sourcepub fn get_string_array(&self, key: &str) -> Option<Vec<&str>>
pub fn get_string_array(&self, key: &str) -> Option<Vec<&str>>
Gets a string array from the license metadata.
Returns None if the key doesn’t exist or the value is not an array.
Non-string elements in the array are filtered out.
§Example
use rust_license_key::prelude::*;
// After validating a license:
// if let Some(modules) = payload.get_string_array("allowed_modules") {
// for module in modules {
// println!("Module: {}", module);
// }
// }Sourcepub fn get_object(&self, key: &str) -> Option<&Map<String, Value>>
pub fn get_object(&self, key: &str) -> Option<&Map<String, Value>>
Gets an object value from the license metadata.
Returns None if the key doesn’t exist or the value is not an object.
Trait Implementations§
Source§impl Clone for LicensePayload
impl Clone for LicensePayload
Source§fn clone(&self) -> LicensePayload
fn clone(&self) -> LicensePayload
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more