Skip to content

Commit e0668ee

Browse files
committed
Add public factory functions to LargeBlobAuthenticationOutput
1 parent e369465 commit e0668ee

File tree

7 files changed

+46
-40
lines changed

7 files changed

+46
-40
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ New features:
99
* Added public builder to `CredentialPropertiesOutput`.
1010
* Added public factory function
1111
`LargeBlobRegistrationOutput.supported(boolean)`.
12+
* Added public factory functions to `LargeBlobAuthenticationOutput`.
1213
* (Experimental) Added option `isSecurePaymentConfirmation(boolean)` to
1314
`FinishAssertionOptions`. When set, `RelyingParty.finishAssertion()` will
1415
adapt the validation logic for a Secure Payment Confirmation (SPC) response

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,43 @@ public static class LargeBlobAuthenticationOutput {
364364
@JsonProperty private final Boolean written;
365365

366366
@JsonCreator
367-
LargeBlobAuthenticationOutput(
367+
private LargeBlobAuthenticationOutput(
368368
@JsonProperty("blob") ByteArray blob, @JsonProperty("written") Boolean written) {
369369
this.blob = blob;
370370
this.written = written;
371371
}
372372

373+
/**
374+
* Create a Large blob storage extension output with the <code>blob</code> output set to the
375+
* given value.
376+
*
377+
* <p>This corresponds to the extension input {@link LargeBlobAuthenticationInput#read()
378+
* LargeBlobAuthenticationInput.read()}.
379+
*
380+
* @see <a
381+
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictdef-authenticationextensionslargebloboutputs">
382+
* dictionary AuthenticationExtensionsLargeBlobOutputs</a>
383+
*/
384+
public static LargeBlobAuthenticationOutput read(final ByteArray blob) {
385+
return new LargeBlobAuthenticationOutput(blob, null);
386+
}
387+
388+
/**
389+
* Create a Large blob storage extension output with the <code>written</code> output set to
390+
* the given value.
391+
*
392+
* <p>This corresponds to the extension input {@link
393+
* LargeBlobAuthenticationInput#write(ByteArray)
394+
* LargeBlobAuthenticationInput.write(ByteArray)}.
395+
*
396+
* @see <a
397+
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#dictdef-authenticationextensionslargebloboutputs">
398+
* dictionary AuthenticationExtensionsLargeBlobOutputs</a>
399+
*/
400+
public static LargeBlobAuthenticationOutput write(final boolean write) {
401+
return new LargeBlobAuthenticationOutput(null, write);
402+
}
403+
373404
/**
374405
* The opaque byte string that was associated with the credential identified by {@link
375406
* PublicKeyCredential#getId()}. Only valid if {@link LargeBlobAuthenticationInput#getRead()}

webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyAssertionSpec.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ import com.yubico.webauthn.data.ByteArray
3939
import com.yubico.webauthn.data.ClientAssertionExtensionOutputs
4040
import com.yubico.webauthn.data.CollectedClientData
4141
import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationInput
42+
import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationOutput
4243
import com.yubico.webauthn.data.Extensions.Uvm.UvmEntry
4344
import com.yubico.webauthn.data.Generators._
4445
import com.yubico.webauthn.data.PublicKeyCredential
4546
import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions
4647
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor
4748
import com.yubico.webauthn.data.PublicKeyCredentialParameters
4849
import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions
49-
import com.yubico.webauthn.data.ReexportHelpers
5050
import com.yubico.webauthn.data.RelyingPartyIdentity
5151
import com.yubico.webauthn.data.UserIdentity
5252
import com.yubico.webauthn.data.UserVerificationRequirement
@@ -2517,8 +2517,7 @@ class RelyingPartyAssertionSpec
25172517
ClientAssertionExtensionOutputs
25182518
.builder()
25192519
.largeBlob(
2520-
ReexportHelpers
2521-
.newLargeBlobAuthenticationOutput(None, Some(true))
2520+
LargeBlobAuthenticationOutput.write(true)
25222521
)
25232522
.build()
25242523
)
@@ -2559,10 +2558,8 @@ class RelyingPartyAssertionSpec
25592558
ClientAssertionExtensionOutputs
25602559
.builder()
25612560
.largeBlob(
2562-
ReexportHelpers.newLargeBlobAuthenticationOutput(
2563-
Some(ByteArray.fromHex("00010203")),
2564-
None,
2565-
)
2561+
LargeBlobAuthenticationOutput
2562+
.read(ByteArray.fromHex("00010203"))
25662563
)
25672564
.build()
25682565
)

webauthn-server-core/src/test/scala/com/yubico/webauthn/RelyingPartyV2AssertionSpec.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ import com.yubico.webauthn.data.ByteArray
3939
import com.yubico.webauthn.data.ClientAssertionExtensionOutputs
4040
import com.yubico.webauthn.data.CollectedClientData
4141
import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationInput
42+
import com.yubico.webauthn.data.Extensions.LargeBlob.LargeBlobAuthenticationOutput
4243
import com.yubico.webauthn.data.Extensions.Uvm.UvmEntry
4344
import com.yubico.webauthn.data.Generators._
4445
import com.yubico.webauthn.data.PublicKeyCredential
4546
import com.yubico.webauthn.data.PublicKeyCredentialCreationOptions
4647
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor
4748
import com.yubico.webauthn.data.PublicKeyCredentialParameters
4849
import com.yubico.webauthn.data.PublicKeyCredentialRequestOptions
49-
import com.yubico.webauthn.data.ReexportHelpers
5050
import com.yubico.webauthn.data.RelyingPartyIdentity
5151
import com.yubico.webauthn.data.UserIdentity
5252
import com.yubico.webauthn.data.UserVerificationRequirement
@@ -2594,8 +2594,7 @@ class RelyingPartyV2AssertionSpec
25942594
ClientAssertionExtensionOutputs
25952595
.builder()
25962596
.largeBlob(
2597-
ReexportHelpers
2598-
.newLargeBlobAuthenticationOutput(None, Some(true))
2597+
LargeBlobAuthenticationOutput.write(true)
25992598
)
26002599
.build()
26012600
)
@@ -2637,10 +2636,8 @@ class RelyingPartyV2AssertionSpec
26372636
ClientAssertionExtensionOutputs
26382637
.builder()
26392638
.largeBlob(
2640-
ReexportHelpers.newLargeBlobAuthenticationOutput(
2641-
Some(ByteArray.fromHex("00010203")),
2642-
None,
2643-
)
2639+
LargeBlobAuthenticationOutput
2640+
.read(ByteArray.fromHex("00010203"))
26442641
)
26452642
.build()
26462643
)

webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ExtensionsSpec.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class ExtensionsSpec
334334
Set("appid", "largeBlob")
335335
)
336336
assertionCred.getClientExtensionResults.getLargeBlob.toScala should equal(
337-
Some(new LargeBlobAuthenticationOutput(null, true))
337+
Some(LargeBlobAuthenticationOutput.write(true))
338338
)
339339
}
340340

@@ -355,9 +355,8 @@ class ExtensionsSpec
355355
)
356356
assertionCred.getClientExtensionResults.getLargeBlob.toScala should equal(
357357
Some(
358-
new LargeBlobAuthenticationOutput(
359-
new ByteArray("Hello, World!".getBytes(StandardCharsets.UTF_8)),
360-
null,
358+
LargeBlobAuthenticationOutput.read(
359+
new ByteArray("Hello, World!".getBytes(StandardCharsets.UTF_8))
361360
)
362361
)
363362
)

webauthn-server-core/src/test/scala/com/yubico/webauthn/data/Generators.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ object Generators {
898898
blob <- arbitrary[ByteArray]
899899
written <- arbitrary[Boolean]
900900
result <- Gen.oneOf(
901-
new LargeBlobAuthenticationOutput(blob, null),
902-
new LargeBlobAuthenticationOutput(null, written),
901+
LargeBlobAuthenticationOutput.read(blob),
902+
LargeBlobAuthenticationOutput.write(written),
903903
)
904904
} yield result)
905905
}

webauthn-server-core/src/test/scala/com/yubico/webauthn/data/ReexportHelpers.scala

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)