| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\Denormalizer; |
| 6 |
|
| 7 |
use function array_key_exists; |
| 8 |
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
| 9 |
use Webauthn\Exception\InvalidDataException; |
| 10 |
use Webauthn\PublicKeyCredentialParameters; |
| 11 |
|
| 12 |
final class PublicKeyCredentialParametersDenormalizer implements DenormalizerInterface |
| 13 |
{ |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed |
| 18 |
{ |
| 19 |
|
| 20 |
if (! array_key_exists('type', $data) || ! array_key_exists('alg', $data)) { |
| 21 |
throw new InvalidDataException($data, 'Missing type or alg'); |
| 22 |
} |
| 23 |
|
| 24 |
return PublicKeyCredentialParameters::create($data['type'], $data['alg']); |
| 25 |
} |
| 26 |
|
| 27 |
public function supportsDenormalization( |
| 28 |
mixed $data, |
| 29 |
string $type, |
| 30 |
?string $format = null, |
| 31 |
array $context = [] |
| 32 |
): bool { |
| 33 |
return $type === PublicKeyCredentialParameters::class; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function getSupportedTypes(?string $format): array |
| 40 |
{ |
| 41 |
return [ |
| 42 |
PublicKeyCredentialParameters::class => true, |
| 43 |
]; |
| 44 |
} |
| 45 |
} |