-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing pieces for moving to 5.0.0
- Loading branch information
Showing
15 changed files
with
199 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webauthn\Denormalizer; | ||
|
||
use Symfony\Component\Serializer\Exception\BadMethodCallException; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Webauthn\Exception\InvalidTrustPathException; | ||
use Webauthn\TrustPath\TrustPath; | ||
use function array_key_exists; | ||
use function in_array; | ||
|
||
final class TrustPathDenormalizer implements DenormalizerInterface, DenormalizerAwareInterface | ||
{ | ||
use DenormalizerAwareTrait; | ||
|
||
private const ALREADY_CALLED = 'TRUST_PATH_PREPROCESS_ALREADY_CALLED'; | ||
|
||
/** | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function denormalize(mixed $data, string $type, string $format = null, array $context = []) | ||
{ | ||
if ($this->denormalizer === null) { | ||
throw new BadMethodCallException('Please set a denormalizer before calling denormalize()!'); | ||
} | ||
array_key_exists('type', $data) || throw InvalidTrustPathException::create('The trust path type is missing'); | ||
$className = $data['type']; | ||
if (class_exists($className) !== true) { | ||
throw InvalidTrustPathException::create( | ||
sprintf('The trust path type "%s" is not supported', $data['type']) | ||
); | ||
} | ||
|
||
$implements = class_implements($className); | ||
if (! in_array(TrustPath::class, $implements, true)) { | ||
throw InvalidTrustPathException::create( | ||
sprintf('The trust path type "%s" is not supported', $data['type']) | ||
); | ||
} | ||
|
||
$context[self::ALREADY_CALLED] = true; | ||
|
||
return $this->denormalizer->denormalize($data, $className, $format, $context); | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool | ||
{ | ||
if ($context[self::ALREADY_CALLED] ?? false) { | ||
return false; | ||
} | ||
|
||
return $type === TrustPath::class; | ||
} | ||
|
||
/** | ||
* @return array<class-string, bool> | ||
*/ | ||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [ | ||
TrustPath::class => false, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.