Skip to content

Commit 491f4f9

Browse files
committed
Replace public constructors with factory functions
1 parent 0e9ea4c commit 491f4f9

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ public AssertionExtensionInputsBuilder prf(
197197
Extensions.Prf.PrfValues eval,
198198
Map<PublicKeyCredentialDescriptor, Extensions.Prf.PrfValues> evalByCredential) {
199199
this.prf =
200-
new Extensions.Prf.PrfAuthenticationInput(
201-
eval, Extensions.Prf.PrfAuthenticationInput.descriptorsToIds(evalByCredential));
200+
Extensions.Prf.PrfAuthenticationInput.evalByCredentialWithFallback(
201+
evalByCredential, eval);
202202
return this;
203203
}
204204

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ public static class PrfValues {
774774
@JsonProperty public final ByteArray second;
775775

776776
@JsonCreator
777-
public PrfValues(
777+
private PrfValues(
778778
@JsonProperty("first") @NonNull final ByteArray first,
779779
@JsonProperty("second") final ByteArray second) {
780780
this.first = first;
@@ -784,6 +784,19 @@ public PrfValues(
784784
public Optional<ByteArray> getSecond() {
785785
return Optional.ofNullable(second);
786786
}
787+
788+
public static PrfValues one(@NonNull ByteArray first) {
789+
return new PrfValues(first, null);
790+
}
791+
792+
public static PrfValues two(@NonNull ByteArray first, @NonNull ByteArray second) {
793+
return new PrfValues(first, second);
794+
}
795+
796+
public static PrfValues oneOrTwo(
797+
@NonNull ByteArray first, @NonNull Optional<ByteArray> second) {
798+
return new PrfValues(first, second.orElse(null));
799+
}
787800
}
788801

789802
/**
@@ -801,7 +814,7 @@ public static class PrfAuthenticationInput {
801814
@JsonProperty private final Map<ByteArray, PrfValues> evalByCredential;
802815

803816
@JsonCreator
804-
public PrfAuthenticationInput(
817+
private PrfAuthenticationInput(
805818
@JsonProperty("eval") PrfValues eval,
806819
@JsonProperty("evalByCredential") Map<ByteArray, PrfValues> evalByCredential) {
807820
this.eval = eval;
@@ -817,7 +830,7 @@ public Optional<Map<ByteArray, PrfValues>> getEvalByCredential() {
817830
return Optional.ofNullable(evalByCredential);
818831
}
819832

820-
static HashMap<ByteArray, PrfValues> descriptorsToIds(
833+
private static HashMap<ByteArray, PrfValues> descriptorsToIds(
821834
Map<PublicKeyCredentialDescriptor, PrfValues> evalByCredential) {
822835
return evalByCredential.entrySet().stream()
823836
.reduce(
@@ -831,6 +844,21 @@ static HashMap<ByteArray, PrfValues> descriptorsToIds(
831844
return a;
832845
});
833846
}
847+
848+
public static PrfAuthenticationInput eval(@NonNull PrfValues eval) {
849+
return new PrfAuthenticationInput(eval, null);
850+
}
851+
852+
public static PrfAuthenticationInput evalByCredential(
853+
@NonNull Map<PublicKeyCredentialDescriptor, PrfValues> evalByCredential) {
854+
return new PrfAuthenticationInput(null, descriptorsToIds(evalByCredential));
855+
}
856+
857+
public static PrfAuthenticationInput evalByCredentialWithFallback(
858+
@NonNull Map<PublicKeyCredentialDescriptor, PrfValues> evalByCredential,
859+
@NonNull PrfValues eval) {
860+
return new PrfAuthenticationInput(eval, descriptorsToIds(evalByCredential));
861+
}
834862
}
835863

836864
/**
@@ -846,13 +874,21 @@ public static class PrfRegistrationInput {
846874
@JsonProperty private final PrfValues eval;
847875

848876
@JsonCreator
849-
public PrfRegistrationInput(@JsonProperty("eval") PrfValues eval) {
877+
private PrfRegistrationInput(@JsonProperty("eval") PrfValues eval) {
850878
this.eval = eval;
851879
}
852880

853881
public Optional<PrfValues> getEval() {
854882
return Optional.ofNullable(eval);
855883
}
884+
885+
public static PrfRegistrationInput enable() {
886+
return new PrfRegistrationInput(null);
887+
}
888+
889+
public static PrfRegistrationInput eval(@NonNull PrfValues eval) {
890+
return new PrfRegistrationInput(eval);
891+
}
856892
}
857893

858894
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public RegistrationExtensionInputsBuilder largeBlob(
364364
* Large blob storage extension (largeBlob)</a>
365365
*/
366366
public RegistrationExtensionInputsBuilder prf(Extensions.Prf.PrfValues eval) {
367-
this.prf = new Extensions.Prf.PrfRegistrationInput(eval);
367+
this.prf = Extensions.Prf.PrfRegistrationInput.eval(eval);
368368
return this;
369369
}
370370

0 commit comments

Comments
 (0)