Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn\Denormalizer;
6
7 use ParagonIE\ConstantTime\Base64UrlSafe;
8 use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
9 use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
10 use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
11 use Webauthn\AttestationStatement\AttestationObject;
12 use Webauthn\AuthenticatorAttestationResponse;
13 use Webauthn\CollectedClientData;
14 use Webauthn\Exception\InvalidDataException;
15 use Webauthn\Util\Base64;
16
17 final class AuthenticatorAttestationResponseDenormalizer implements DenormalizerInterface, DenormalizerAwareInterface
18 {
19 use DenormalizerAwareTrait;
20
21 /**
22 * @throws InvalidDataException
23 */
24 public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
25 {
26 /** @var array{clientDataJSON: string, attestationObject: string, transports?: string[]} $data */
27 $data['clientDataJSON'] = Base64UrlSafe::decodeNoPadding($data['clientDataJSON']);
28 $data['attestationObject'] = Base64::decode($data['attestationObject']);
29
30 /** @var CollectedClientData $clientDataJSON */
31 $clientDataJSON = $this->denormalizer->denormalize(
32 $data['clientDataJSON'],
33 CollectedClientData::class,
34 $format,
35 $context
36 );
37 /** @var AttestationObject $attestationObject */
38 $attestationObject = $this->denormalizer->denormalize(
39 $data['attestationObject'],
40 AttestationObject::class,
41 $format,
42 $context
43 );
44
45 return AuthenticatorAttestationResponse::create(
46 $clientDataJSON,
47 $attestationObject,
48 $data['transports'] ?? [],
49 );
50 }
51
52 public function supportsDenormalization(
53 mixed $data,
54 string $type,
55 ?string $format = null,
56 array $context = []
57 ): bool {
58 return $type === AuthenticatorAttestationResponse::class;
59 }
60
61 /**
62 * @return array<class-string, bool>
63 */
64 public function getSupportedTypes(?string $format): array
65 {
66 return [
67 AuthenticatorAttestationResponse::class => true,
68 ];
69 }
70 }