Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorResponseDenormalizer.php

raw symbols SCIP
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\DenormalizerAwareInterface;
9 use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
10 use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
11 use Webauthn\AuthenticatorAssertionResponse;
12 use Webauthn\AuthenticatorAttestationResponse;
13 use Webauthn\AuthenticatorResponse;
14 use Webauthn\Exception\InvalidDataException;
15
16 final class AuthenticatorResponseDenormalizer implements DenormalizerInterface, DenormalizerAwareInterface
17 {
18 use DenormalizerAwareTrait;
19
20 /**
21 * @throws InvalidDataException
22 */
23 public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
24 {
25 /** @var array<string, mixed> $data */
26 $realType = match (true) {
27 array_key_exists('attestationObject', $data) => AuthenticatorAttestationResponse::class,
28 array_key_exists('signature', $data) => AuthenticatorAssertionResponse::class,
29 default => throw InvalidDataException::create($data, 'Unable to create the response object'),
30 };
31
32 return $this->denormalizer->denormalize($data, $realType, $format, $context);
33 }
34
35 public function supportsDenormalization(
36 mixed $data,
37 string $type,
38 ?string $format = null,
39 array $context = []
40 ): bool {
41 return $type === AuthenticatorResponse::class;
42 }
43
44 /**
45 * @return array<class-string, bool>
46 */
47 public function getSupportedTypes(?string $format): array
48 {
49 return [
50 AuthenticatorResponse::class => true,
51 ];
52 }
53 }