pub struct LicenseValidator { /* private fields */ }Expand description
Validator for checking license constraints against runtime context.
The validator performs comprehensive checking of all license constraints and produces detailed validation results suitable for logging and application logic.
§Example
use rust_license_key::validator::LicenseValidator;
use rust_license_key::models::ValidationContext;
use rust_license_key::crypto::PublicKey;
use semver::Version;
// Create validator with the embedded public key
// let public_key = PublicKey::from_base64("...").unwrap();
// let validator = LicenseValidator::new(public_key);
// Set up the validation context
// let context = ValidationContext::new()
// .with_hostname("myserver.example.com")
// .with_software_version(Version::new(1, 2, 3))
// .with_feature("premium");
// Validate the license
// let result = validator.validate_json(&license_json, &context).unwrap();
// if result.is_valid {
// println!("License is valid for {} more days", result.days_remaining().unwrap_or(i64::MAX));
// }Implementations§
Source§impl LicenseValidator
impl LicenseValidator
Sourcepub fn new(public_key: PublicKey) -> Self
pub fn new(public_key: PublicKey) -> Self
Creates a new validator with the given public key.
§Arguments
public_key- The publisher’s public key for signature verification.
Sourcepub fn from_public_key_base64(public_key_base64: &str) -> Result<Self>
pub fn from_public_key_base64(public_key_base64: &str) -> Result<Self>
Creates a new validator from a base64-encoded public key.
§Arguments
public_key_base64- The base64-encoded public key string.
Sourcepub fn validate_json(
&self,
license_json: &str,
context: &ValidationContext,
) -> Result<ValidationResult>
pub fn validate_json( &self, license_json: &str, context: &ValidationContext, ) -> Result<ValidationResult>
Validates a license from a JSON string.
This is the primary validation method. It:
- Parses and verifies the license signature.
- Checks all constraints against the provided context.
- Returns a comprehensive validation result.
§Arguments
license_json- The JSON string containing the signed license.context- The runtime context to validate against.
§Returns
A ValidationResult indicating whether the license is valid and
providing detailed information about any failures.
Sourcepub fn validate_payload(
&self,
payload: &LicensePayload,
context: &ValidationContext,
) -> ValidationResult
pub fn validate_payload( &self, payload: &LicensePayload, context: &ValidationContext, ) -> ValidationResult
Validates a license payload directly.
Use this when you already have a parsed and verified payload. This method assumes the signature has already been verified.
§Arguments
payload- The license payload to validate.context- The runtime context to validate against.
§Returns
A ValidationResult with detailed status information.
Sourcepub fn parser(&self) -> &LicenseParser
pub fn parser(&self) -> &LicenseParser
Returns a reference to the underlying parser.
Trait Implementations§
Source§impl Clone for LicenseValidator
impl Clone for LicenseValidator
Source§fn clone(&self) -> LicenseValidator
fn clone(&self) -> LicenseValidator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more