pub struct CryptoVerifier { /* private fields */ }Expand description
Algorithm-agnostic license verifier that automatically selects the correct algorithm
This verifier uses the algorithm identifier stored in the license to select the appropriate signature verification algorithm. This enables support for multiple signature algorithms (RSA-SHA256, Ed25519, etc.) with automatic detection.
§Example
use licenz_core::verifier::CryptoVerifier;
use std::collections::HashMap;
// Create verifier with multiple public keys
let mut keys = HashMap::new();
keys.insert("RSA-SHA256".to_string(), rsa_public_key_pem.to_string());
keys.insert("Ed25519".to_string(), ed25519_public_key_pem.to_string());
let verifier = CryptoVerifier::new(keys);
let result = verifier.validate(&license);Implementations§
Source§impl CryptoVerifier
impl CryptoVerifier
Sourcepub fn new(public_keys: HashMap<String, String>) -> Self
pub fn new(public_keys: HashMap<String, String>) -> Self
Create a new crypto verifier with multiple public keys
§Arguments
public_keys- Map of algorithm ID to public key PEM
Sourcepub fn from_pem(pem: &str) -> Result<Self>
pub fn from_pem(pem: &str) -> Result<Self>
Create a verifier from a single PEM string, auto-detecting the algorithm
This tries to parse the key as RSA first (for backward compatibility), then falls back to Ed25519.
Sourcepub fn from_pem_file(path: &Path) -> Result<Self>
pub fn from_pem_file(path: &Path) -> Result<Self>
Create a verifier from a PEM file
Sourcepub fn with_public_key(self, algorithm_id: &str, pem: &str) -> Self
pub fn with_public_key(self, algorithm_id: &str, pem: &str) -> Self
Add a public key for a specific algorithm
Sourcepub fn with_hardware_info(self, info: HardwareInfo) -> Self
pub fn with_hardware_info(self, info: HardwareInfo) -> Self
Set custom hardware info (useful for testing or manual override)
Sourcepub fn with_hardware_environment(
self,
env: Arc<dyn HardwareEnvironment>,
) -> Self
pub fn with_hardware_environment( self, env: Arc<dyn HardwareEnvironment>, ) -> Self
Use a custom HardwareEnvironment.
Sourcepub fn load_license(&self, path: &Path) -> Result<SignedLicense>
pub fn load_license(&self, path: &Path) -> Result<SignedLicense>
Load a license from a file (auto-detects format)
Sourcepub fn parse_license(&self, data: &[u8]) -> Result<SignedLicense>
pub fn parse_license(&self, data: &[u8]) -> Result<SignedLicense>
Parse a license from bytes (auto-detects format)
Sourcepub fn verify_signature(&self, license: &SignedLicense) -> Result<()>
pub fn verify_signature(&self, license: &SignedLicense) -> Result<()>
Verify the cryptographic signature of a license
Automatically selects the algorithm based on the license’s algorithm field.
Sourcepub fn verify_expiration(&self, license: &SignedLicense) -> Result<()>
pub fn verify_expiration(&self, license: &SignedLicense) -> Result<()>
Verify that the license has not expired
Sourcepub fn verify_hardware(&self, license: &SignedLicense) -> Result<()>
pub fn verify_hardware(&self, license: &SignedLicense) -> Result<()>
Verify hardware binding
Sourcepub fn validate(&self, license: &SignedLicense) -> Result<()>
pub fn validate(&self, license: &SignedLicense) -> Result<()>
Perform full license validation
This verifies:
- Cryptographic signature (algorithm auto-selected from license)
- Expiration date
- Hardware binding (if enabled)
Sourcepub fn load_and_validate(&self, path: &Path) -> Result<SignedLicense>
pub fn load_and_validate(&self, path: &Path) -> Result<SignedLicense>
Load and validate a license from a file
Sourcepub fn validate_detailed(&self, license: &SignedLicense) -> ValidationResult
pub fn validate_detailed(&self, license: &SignedLicense) -> ValidationResult
Perform detailed validation and return a result
Trait Implementations§
Source§impl Clone for CryptoVerifier
impl Clone for CryptoVerifier
Source§fn clone(&self) -> CryptoVerifier
fn clone(&self) -> CryptoVerifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more