| 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\AttestedCredentialData; |
| 12 |
|
| 13 |
final class AttestedCredentialDataNormalizer implements NormalizerInterface, NormalizerAwareInterface |
| 14 |
{ |
| 15 |
use NormalizerAwareTrait; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public function normalize(mixed $data, ?string $format = null, array $context = []): array |
| 21 |
{ |
| 22 |
assert($data instanceof AttestedCredentialData); |
| 23 |
$result = [ |
| 24 |
'aaguid' => $this->normalizer->normalize($data->aaguid, $format, $context), |
| 25 |
'credentialId' => base64_encode($data->credentialId), |
| 26 |
]; |
| 27 |
if ($data->credentialPublicKey !== null) { |
| 28 |
$result['credentialPublicKey'] = base64_encode($data->credentialPublicKey); |
| 29 |
} |
| 30 |
|
| 31 |
return $result; |
| 32 |
} |
| 33 |
|
| 34 |
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool |
| 35 |
{ |
| 36 |
return $data instanceof AttestedCredentialData; |
| 37 |
} |
| 38 |
|
| 39 |
public function getSupportedTypes(?string $format): array |
| 40 |
{ |
| 41 |
return [ |
| 42 |
AttestedCredentialData::class => true, |
| 43 |
]; |
| 44 |
} |
| 45 |
} |