| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Webauthn\Denormalizer; |
| 6 |
|
| 7 |
use function assert; |
| 8 |
use function count; |
| 9 |
use ParagonIE\ConstantTime\Base64UrlSafe; |
| 10 |
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
| 11 |
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
| 12 |
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
| 13 |
use Webauthn\PublicKeyCredentialDescriptor; |
| 14 |
|
| 15 |
final class PublicKeyCredentialDescriptorNormalizer implements NormalizerInterface, NormalizerAwareInterface |
| 16 |
{ |
| 17 |
use NormalizerAwareTrait; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public function normalize(mixed $data, ?string $format = null, array $context = []): array |
| 23 |
{ |
| 24 |
assert($data instanceof PublicKeyCredentialDescriptor); |
| 25 |
$result = [ |
| 26 |
'type' => $data->type, |
| 27 |
'id' => Base64UrlSafe::encodeUnpadded($data->id), |
| 28 |
]; |
| 29 |
if (count($data->transports) !== 0) { |
| 30 |
$result['transports'] = $data->transports; |
| 31 |
} |
| 32 |
|
| 33 |
return $result; |
| 34 |
} |
| 35 |
|
| 36 |
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool |
| 37 |
{ |
| 38 |
return $data instanceof PublicKeyCredentialDescriptor; |
| 39 |
} |
| 40 |
|
| 41 |
public function getSupportedTypes(?string $format): array |
| 42 |
{ |
| 43 |
return [ |
| 44 |
PublicKeyCredentialDescriptor::class => true, |
| 45 |
]; |
| 46 |
} |
| 47 |
} |