Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Webauthn\Denormalizer;
6
7 use function assert;
8 use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
9 use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
10 use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
11 use Webauthn\PublicKeyCredentialDescriptor;
12 use Webauthn\Signal\AllAcceptedCredentials;
13
14 class SignalAllAcceptedCredentialsDenormalizer implements NormalizerInterface, NormalizerAwareInterface
15 {
16 use NormalizerAwareTrait;
17
18 /**
19 * @return array<class-string, bool>
20 */
21 public function getSupportedTypes(?string $format): array
22 {
23 return [
24 AllAcceptedCredentials::class => true,
25 ];
26 }
27
28 /**
29 * @return array<string, mixed>
30 */
31 public function normalize(mixed $data, ?string $format = null, array $context = []): array
32 {
33 assert($data instanceof AllAcceptedCredentials);
34
35 /** @var array<string, mixed> $normalized_rp */
36 $normalized_rp = $this->normalizer->normalize($data->rp, $format, $context);
37
38 /** @var array<string, mixed> $normalized_user */
39 $normalized_user = $this->normalizer->normalize($data->user, $format, $context);
40
41 /** @var array<int, array{id: string, type: string}> $normalized_credentials */
42 $normalized_credentials = array_map(
43 fn (PublicKeyCredentialDescriptor $credential) => $this->normalizer->normalize(
44 $credential,
45 $format,
46 $context
47 ),
48 $data->allAcceptedCredentials
49 );
50
51 return [
52 'rpId' => $normalized_rp['id'],
53 'userId' => $normalized_user['id'],
54 'allAcceptedCredentialIds' => array_map(
55 static fn (array $credential): string => $credential['id'],
56 $normalized_credentials
57 ),
58 ];
59 }
60
61 public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
62 {
63 return $data instanceof AllAcceptedCredentials;
64 }
65 }