pub struct Decoder { /* private fields */ }Expand description
Builder for decoding Claim 169 credentials from QR strings.
The decoder follows a builder pattern where configuration methods return Self
and the final decode() method consumes the builder to produce the result.
§Operation Order
When both decryption and verification are configured, the credential is always decrypted first, then verified (reverse of encoding), regardless of the order in which builder methods are called.
§Security
- By default, decoding requires signature verification
- Use
allow_unverified()to explicitly opt out - Decompression is limited to prevent zip bomb attacks (default: 64KB)
§Example
use claim169_core::Decoder;
let result = Decoder::new("6BF5YZB2...")
.verify_with_ed25519(&public_key)?
.decode()?;
println!("ID: {:?}", result.claim169.id);
println!("Verified: {:?}", result.verification_status);Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn verify_with<V: SignatureVerifier + 'static>(self, verifier: V) -> Self
pub fn verify_with<V: SignatureVerifier + 'static>(self, verifier: V) -> Self
Verify with a custom verifier implementation.
Use this method for HSM integration or custom cryptographic backends.
§Arguments
verifier- A type implementing theSignatureVerifiertrait
§Example
let decoder = Decoder::new(qr_text)
.verify_with(hsm_verifier);Sourcepub fn verify_with_ed25519(self, public_key: &[u8]) -> Result<Self>
pub fn verify_with_ed25519(self, public_key: &[u8]) -> Result<Self>
Verify with an Ed25519 public key.
The key is validated immediately and an error is returned if invalid.
§Arguments
public_key- 32-byte Ed25519 public key
§Errors
Returns an error if the public key is invalid or represents a weak key.
§Example
let decoder = Decoder::new(qr_text)
.verify_with_ed25519(&public_key)?;Sourcepub fn verify_with_ed25519_pem(self, pem: &str) -> Result<Self>
pub fn verify_with_ed25519_pem(self, pem: &str) -> Result<Self>
Sourcepub fn verify_with_ecdsa_p256(self, public_key: &[u8]) -> Result<Self>
pub fn verify_with_ecdsa_p256(self, public_key: &[u8]) -> Result<Self>
Sourcepub fn verify_with_ecdsa_p256_pem(self, pem: &str) -> Result<Self>
pub fn verify_with_ecdsa_p256_pem(self, pem: &str) -> Result<Self>
Sourcepub fn decrypt_with<D: Decryptor + 'static>(self, decryptor: D) -> Self
pub fn decrypt_with<D: Decryptor + 'static>(self, decryptor: D) -> Self
Sourcepub fn decrypt_with_aes256(self, key: &[u8]) -> Result<Self>
pub fn decrypt_with_aes256(self, key: &[u8]) -> Result<Self>
Sourcepub fn decrypt_with_aes128(self, key: &[u8]) -> Result<Self>
pub fn decrypt_with_aes128(self, key: &[u8]) -> Result<Self>
Sourcepub fn allow_unverified(self) -> Self
pub fn allow_unverified(self) -> Self
Sourcepub fn skip_biometrics(self) -> Self
pub fn skip_biometrics(self) -> Self
Skip biometric fields during decoding.
This speeds up decoding by not parsing fingerprint, iris, face, palm, and voice biometric data.
Sourcepub fn without_timestamp_validation(self) -> Self
pub fn without_timestamp_validation(self) -> Self
Disable timestamp validation.
By default, the decoder validates that:
- The credential has not expired (
expclaim) - The credential is valid for use (
nbfclaim)
Use this method to skip these checks (e.g., for offline scenarios).
Sourcepub fn clock_skew_tolerance(self, seconds: i64) -> Self
pub fn clock_skew_tolerance(self, seconds: i64) -> Self
Set the clock skew tolerance for timestamp validation.
This allows for some difference between the system clock and the
issuer’s clock when validating exp and nbf claims.
§Arguments
seconds- Number of seconds to tolerate (default: 0)
Sourcepub fn max_decompressed_bytes(self, bytes: usize) -> Self
pub fn max_decompressed_bytes(self, bytes: usize) -> Self
Set the maximum decompressed size.
This protects against zip bomb attacks by limiting how much data can be decompressed from the QR payload.
§Arguments
bytes- Maximum decompressed size in bytes (default: 65536)
Sourcepub fn decode(self) -> Result<DecodeResult>
pub fn decode(self) -> Result<DecodeResult>
Decode the QR text and return the result.
This method consumes the decoder and performs the full decoding pipeline:
Base45 → zlib → COSE_Encrypt0 → COSE_Sign1 → CWT → Claim169§Errors
Returns an error if:
- Neither a verifier nor
allow_unverified()was configured - Base45 decoding fails
- Decompression fails or exceeds the limit
- COSE structure is invalid
- Signature verification fails
- Decryption fails
- CWT parsing fails
- Timestamp validation fails
§Example
let result = Decoder::new(qr_text)
.verify_with_ed25519(&public_key)?
.decode()?;
println!("Name: {:?}", result.claim169.full_name);