LicensePayload

Struct LicensePayload 

Source
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: u32

Version of the license format for forward compatibility. This allows the library to reject incompatible future formats.

§license_id: String

Unique identifier for this specific license. Should be a UUID or similar unique identifier.

§customer_id: String

Identifier 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: LicenseConstraints

All 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

Source

pub fn id(&self) -> &str

Returns the license ID as a string slice.

Source

pub fn customer(&self) -> &str

Returns the customer ID as a string slice.

Source

pub fn is_version_supported(&self) -> bool

Checks if the license format version is supported by this library.

Source

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);
// }
Source

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));
Source

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);
// }
Source

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");
Source

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);
// }
Source

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);
Source

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.

Source

pub fn get_u64_or(&self, key: &str, default: u64) -> u64

Gets a u64 value from the license metadata, or returns a default.

Source

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.

Source

pub fn get_f64_or(&self, key: &str, default: f64) -> f64

Gets an f64 value from the license metadata, or returns a default.

Source

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.

Source

pub fn get_bool_or(&self, key: &str, default: bool) -> bool

Gets a boolean value from the license metadata, or returns a default.

Source

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);
//     }
// }
Source

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);
//     }
// }
Source

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.

Source

pub fn has_key(&self, key: &str) -> bool

Checks if a key exists in the license metadata.

§Example
use rust_license_key::prelude::*;

// After validating a license:
// if payload.has_key("enterprise_features") {
//     // Enable enterprise features
// }
Source

pub fn keys(&self) -> impl Iterator<Item = &String>

Returns all metadata keys.

Returns an empty iterator if no metadata is present.

Trait Implementations§

Source§

impl Clone for LicensePayload

Source§

fn clone(&self) -> LicensePayload

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LicensePayload

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for LicensePayload

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for LicensePayload

Source§

fn eq(&self, other: &LicensePayload) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for LicensePayload

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for LicensePayload

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,