Web IDL support 2/N: response JSON serialization #155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is the second in a series (follows #138) and adds JSON serialization for WebAuthn responses - the inverse of the existing JSON request parsing functionality.
Changes
New Response Serialization Infrastructure
WebAuthnIDLResponsetrait - Providesto_json()andto_inner_model()methods for converting responses to JSON formatJsonFormatenum - Supports both minified and prettified JSON outputResponseSerializationError- Error type for serialization failuresNew JSON Response Models (per WebAuthn Level 3 spec)
RegistrationResponseJSON- ForMakeCredentialResponseserializationAuthenticationResponseJSON- ForAssertionserializationAuthenticatorAttestationResponseJSON- Attestation response detailsAuthenticatorAssertionResponseJSON- Assertion response detailsAuthenticationExtensionsClientOutputsJSON- Extension output serializationRequest Structure Refactoring
Refactored
MakeCredentialRequestandGetAssertionRequestto enable client data generation on-the-fly:hash: Vec<u8>withchallenge: Vec<u8>- Store raw challenge instead of pre-computed hashorigin: Stringfield - Store origin explicitlycross_origin: Option<bool>field - Optional cross-origin flagclient_data: ClientDatafield - No longer needed as separate fieldclient_data()- BuildsClientDatainternallyclient_data_hash()- Computes SHA-256 hash on demandclient_data_json()- Returns JSON bytes for response serializationImplementation Details
WebAuthnIDLResponseforMakeCredentialResponsewith full attestation object CBOR serializationWebAuthnIDLResponseforAssertionwith signature and authenticator data handlingcredProps,hmacCreateSecret,hmacGetSecret,largeBlob,prfSerializederives to attestation statement types for CBOR encodingUpdated Files
client_data_hash()Testing
webauthn_json_hid.rsexample to demonstrate JSON response outputExample Usage