Debian Codegraph @

lib/3rdParty/composer/web-auth/webauthn-lib/src/Denormalizer/AuthenticatorAssertionResponseDenormalizer.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\AuthenticatorAssertionResponse;
13 use Webauthn\AuthenticatorData;
14 use Webauthn\CollectedClientData;
15 use Webauthn\Exception\InvalidDataException;
16 use Webauthn\Util\Base64;
17
18 final class AuthenticatorAssertionResponseDenormalizer implements DenormalizerInterface, DenormalizerAwareInterface
19 {
20 use DenormalizerAwareTrait;
21
22 /**
23 * @throws InvalidDataException
24 */
25 public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
26 {
27 /** @var array{authenticatorData: string, signature: string, clientDataJSON: string, userHandle?: ?string, attestationObject?: string} $data */
28 $data['authenticatorData'] = Base64::decode($data['authenticatorData']);
29 $data['signature'] = Base64::decode($data['signature']);
30 $data['clientDataJSON'] = Base64UrlSafe::decodeNoPadding($data['clientDataJSON']);
31 $userHandle = $data['userHandle'] ?? null;
32 if ($userHandle !== '' && $userHandle !== null) {
33 $userHandle = Base64::decode($userHandle);
34 }
35
36 /** @var CollectedClientData $clientDataJSON */
37 $clientDataJSON = $this->denormalizer->denormalize(
38 $data['clientDataJSON'],
39 CollectedClientData::class,
40 $format,
41 $context
42 );
43 /** @var AuthenticatorData $authenticatorData */
44 $authenticatorData = $this->denormalizer->denormalize(
45 $data['authenticatorData'],
46 AuthenticatorData::class,
47 $format,
48 $context
49 );
50
51 return AuthenticatorAssertionResponse::create(
52 $clientDataJSON,
53 $authenticatorData,
54 $data['signature'],
55 $userHandle ?? null,
56 ! isset($data['attestationObject']) ? null : $this->denormalizer->denormalize(
57 $data['attestationObject'],
58 AttestationObject::class,
59 $format,
60 $context
61 ),
62 );
63 }
64
65 public function supportsDenormalization(
66 mixed $data,
67 string $type,
68 ?string $format = null,
69 array $context = []
70 ): bool {
71 return $type === AuthenticatorAssertionResponse::class;
72 }
73
74 /**
75 * @return array<class-string, bool>
76 */
77 public function getSupportedTypes(?string $format): array
78 {
79 return [
80 AuthenticatorAssertionResponse::class => true,
81 ];
82 }
83 }