pub struct LicenseParser { /* private fields */ }Expand description
Parser for loading and verifying signed licenses.
The parser takes a public key and uses it to verify license signatures. Only licenses signed by the corresponding private key will be accepted.
§Security
The parser only accepts licenses with valid signatures. Any tampering with the license payload will cause signature verification to fail.
§Example
use rust_license_key::parser::LicenseParser;
use rust_license_key::crypto::PublicKey;
// The public key embedded in your application
let public_key_base64 = "..."; // Your public key here
// In a real application:
// let public_key = PublicKey::from_base64(public_key_base64).unwrap();
// let parser = LicenseParser::new(public_key);
// let license = parser.parse_json(&license_file_contents).unwrap();Implementations§
Source§impl LicenseParser
impl LicenseParser
Sourcepub fn new(public_key: PublicKey) -> Self
pub fn new(public_key: PublicKey) -> Self
Creates a new license parser 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>
Sourcepub fn parse_json(&self, json: &str) -> Result<LicensePayload>
pub fn parse_json(&self, json: &str) -> Result<LicensePayload>
Parses a signed license from a JSON string.
This method:
- Parses the JSON structure.
- Verifies the cryptographic signature.
- Decodes the license payload.
- Validates the license format version.
§Arguments
json- The JSON string containing the signed license.
§Returns
The verified and decoded license payload.
§Errors
Returns an error if:
- The JSON is malformed.
- The signature is invalid.
- The payload cannot be decoded.
- The license version is not supported.
Sourcepub fn parse_signed_license(
&self,
signed_license: &SignedLicense,
) -> Result<LicensePayload>
pub fn parse_signed_license( &self, signed_license: &SignedLicense, ) -> Result<LicensePayload>
Sourcepub fn decode_unverified(&self, json: &str) -> Result<(LicensePayload, bool)>
pub fn decode_unverified(&self, json: &str) -> Result<(LicensePayload, bool)>
Attempts to decode a license without signature verification.
§Warning
This method bypasses security and should only be used for debugging or inspection purposes. Never use the returned payload for access control decisions.
§Arguments
json- The JSON string containing the signed license.
§Returns
The decoded payload and a boolean indicating if the signature was valid.
Sourcepub fn public_key(&self) -> &PublicKey
pub fn public_key(&self) -> &PublicKey
Returns a reference to the parser’s public key.
Trait Implementations§
Source§impl Clone for LicenseParser
impl Clone for LicenseParser
Source§fn clone(&self) -> LicenseParser
fn clone(&self) -> LicenseParser
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more