Skip to content

Commit a6d89fd

Browse files
committed
Optimize getParsedAuthenticatorData()
1 parent 350c784 commit a6d89fd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

webauthn-server-core/src/main/java/com/yubico/webauthn/data/AuthenticatorAssertionResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public class AuthenticatorAssertionResponse implements AuthenticatorResponse {
7272
*/
7373
private final ByteArray userHandle;
7474

75+
// This overrides the default getter in AuthenticatorResponse which re-parses the authenticator
76+
// data on every invocation. This "optimization" has no measurable impact on performance, but it
77+
// seems rude to obviously waste cycles for nothing.
78+
private final transient AuthenticatorData parsedAuthenticatorData;
79+
7580
@NonNull
7681
@Getter(onMethod = @__({@Override}))
7782
private final transient CollectedClientData clientData;
@@ -85,6 +90,7 @@ private AuthenticatorAssertionResponse(
8590
@JsonProperty("userHandle") final ByteArray userHandle)
8691
throws IOException, Base64UrlException {
8792
this.authenticatorData = authenticatorData;
93+
this.parsedAuthenticatorData = new AuthenticatorData(authenticatorData);
8894
this.clientDataJSON = clientDataJSON;
8995
this.signature = signature;
9096
this.userHandle = userHandle;

webauthn-server-core/src/main/java/com/yubico/webauthn/data/AuthenticatorAttestationResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ private AuthenticatorAttestationResponse(
113113
this.clientData = new CollectedClientData(clientDataJSON);
114114
}
115115

116+
// The default getter in AuthenticatorResponse re-parses the authenticator data on every
117+
// invocation. This "optimization" override has no measurable impact on performance, but it seems
118+
// rude to obviously waste cycles for nothing.
119+
@Override
120+
public AuthenticatorData getParsedAuthenticatorData() {
121+
return attestation.getAuthenticatorData();
122+
}
123+
116124
public static AuthenticatorAttestationResponseBuilder.MandatoryStages builder() {
117125
return new AuthenticatorAttestationResponseBuilder.MandatoryStages();
118126
}

0 commit comments

Comments
 (0)