|
1 | 1 | package com.yubico.fido.metadata; |
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 4 | +import com.fasterxml.jackson.core.JacksonException; |
4 | 5 | import com.fasterxml.jackson.core.JsonGenerator; |
5 | 6 | import com.fasterxml.jackson.core.JsonParser; |
6 | 7 | import com.fasterxml.jackson.databind.DeserializationContext; |
|
19 | 20 | import java.util.Optional; |
20 | 21 | import java.util.Set; |
21 | 22 | import java.util.stream.Collectors; |
| 23 | +import java.util.stream.Stream; |
22 | 24 | import lombok.Builder; |
23 | 25 | import lombok.NonNull; |
24 | 26 | import lombok.Value; |
@@ -116,6 +118,7 @@ public class AuthenticatorGetInfo { |
116 | 118 | * href="https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#authenticatorGetInfo">Client |
117 | 119 | * to Authenticator Protocol (CTAP) §6.4. authenticatorGetInfo (0x04)</a> |
118 | 120 | */ |
| 121 | + @JsonDeserialize(using = ListPublicKeyCredentialParametersIgnoringUnknownValuesDeserializer.class) |
119 | 122 | List<PublicKeyCredentialParameters> algorithms; |
120 | 123 |
|
121 | 124 | /** |
@@ -377,4 +380,44 @@ public void serialize( |
377 | 380 | value.stream().reduce(0, (acc, next) -> acc | next.getValue(), (a, b) -> a | b)); |
378 | 381 | } |
379 | 382 | } |
| 383 | + |
| 384 | + @Value |
| 385 | + @JsonDeserialize(using = PublicKeyCredentialParametersIgnoringUnknownValues.Deserializer.class) |
| 386 | + private static class PublicKeyCredentialParametersIgnoringUnknownValues { |
| 387 | + PublicKeyCredentialParameters value; |
| 388 | + |
| 389 | + private static class Deserializer |
| 390 | + extends JsonDeserializer<PublicKeyCredentialParametersIgnoringUnknownValues> { |
| 391 | + @Override |
| 392 | + public PublicKeyCredentialParametersIgnoringUnknownValues deserialize( |
| 393 | + JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException { |
| 394 | + try { |
| 395 | + return new PublicKeyCredentialParametersIgnoringUnknownValues( |
| 396 | + p.readValueAs(PublicKeyCredentialParameters.class)); |
| 397 | + } catch (IOException e) { |
| 398 | + return null; |
| 399 | + } |
| 400 | + } |
| 401 | + } |
| 402 | + } |
| 403 | + |
| 404 | + private static class ListPublicKeyCredentialParametersIgnoringUnknownValuesDeserializer |
| 405 | + extends JsonDeserializer<List<PublicKeyCredentialParameters>> { |
| 406 | + @Override |
| 407 | + public List<PublicKeyCredentialParameters> deserialize( |
| 408 | + JsonParser p, DeserializationContext ctxt) throws IOException { |
| 409 | + PublicKeyCredentialParametersIgnoringUnknownValues[] pkcpiuvs = |
| 410 | + p.readValueAs(PublicKeyCredentialParametersIgnoringUnknownValues[].class); |
| 411 | + return Arrays.stream(pkcpiuvs) |
| 412 | + .flatMap( |
| 413 | + pkcpiuv -> { |
| 414 | + if (pkcpiuv != null && pkcpiuv.value != null) { |
| 415 | + return Stream.of(pkcpiuv.value); |
| 416 | + } else { |
| 417 | + return Stream.empty(); |
| 418 | + } |
| 419 | + }) |
| 420 | + .collect(Collectors.toList()); |
| 421 | + } |
| 422 | + } |
380 | 423 | } |
0 commit comments