diff --git a/performance/JWE/EncryptionBench.php b/performance/JWE/EncryptionBench.php index 217e9edd..e473553f 100644 --- a/performance/JWE/EncryptionBench.php +++ b/performance/JWE/EncryptionBench.php @@ -14,7 +14,6 @@ namespace Jose\Performance\JWE; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; use Jose\Component\Encryption\Algorithm\ContentEncryption; @@ -38,12 +37,10 @@ abstract class EncryptionBench private $contentEncryptionAlgorithmsManager; private $keyEncryptionAlgorithmsManager; private $compressionMethodsManager; - private $jsonConverter; private $serializerManager; public function init() { - $this->jsonConverter = new StandardConverter(); $this->keyEncryptionAlgorithmsManager = new AlgorithmManager([ new KeyEncryption\A128KW(), new KeyEncryption\A192KW(), @@ -77,9 +74,9 @@ public function init() new Compression\ZLib(), ]); $this->serializerManager = new JWESerializerManager([ - new CompactSerializer($this->jsonConverter), - new JSONFlattenedSerializer($this->jsonConverter), - new JSONGeneralSerializer($this->jsonConverter), + new CompactSerializer(), + new JSONFlattenedSerializer(), + new JSONGeneralSerializer(), ]); } @@ -90,7 +87,6 @@ public function init() public function encryption(array $params) { $jweBuilder = new JWEBuilder( - $this->jsonConverter, $this->getKeyEncryptionAlgorithmsManager(), $this->getContentEncryptionAlgorithmsManager(), $this->getCompressionMethodsManager() diff --git a/performance/JWS/SignatureBench.php b/performance/JWS/SignatureBench.php index a70e2163..a8b510c4 100644 --- a/performance/JWS/SignatureBench.php +++ b/performance/JWS/SignatureBench.php @@ -14,7 +14,6 @@ namespace Jose\Performance\JWS; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm; use Jose\Component\Signature\Algorithm\SignatureAlgorithm; @@ -33,12 +32,10 @@ abstract class SignatureBench { private $payload = "It\xe2\x80\x99s a dangerous business, Frodo, going out your door. You step onto the road, and if you don't keep your feet, there\xe2\x80\x99s no knowing where you might be swept off to."; private $signatureAlgorithmsManager; - private $jsonConverter; private $serializerManager; public function init() { - $this->jsonConverter = new StandardConverter(); $this->signatureAlgorithmsManager = new AlgorithmManager([ new Algorithm\HS256(), new Algorithm\HS384(), @@ -56,9 +53,9 @@ public function init() new Algorithm\EdDSA(), ]); $this->serializerManager = new JWSSerializerManager([ - new CompactSerializer($this->jsonConverter), - new JSONFlattenedSerializer($this->jsonConverter), - new JSONGeneralSerializer($this->jsonConverter), + new CompactSerializer(), + new JSONFlattenedSerializer(), + new JSONGeneralSerializer(), ]); } @@ -68,7 +65,7 @@ public function init() */ public function sign(array $params) { - $jwsBuilder = new JWSBuilder($this->jsonConverter, $this->signatureAlgorithmsManager); + $jwsBuilder = new JWSBuilder($this->signatureAlgorithmsManager); $jwsBuilder ->withPayload($this->payload) ->addSignature($this->getPrivateKey(), ['alg' => $params['algorithm']]) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a48e21d7..1166d91e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" bootstrap="vendor/autoload.php" colors="true"> diff --git a/src/Bundle/JoseFramework/Controller/JWKSetControllerFactory.php b/src/Bundle/JoseFramework/Controller/JWKSetControllerFactory.php index bd5dc38a..d0ed5178 100644 --- a/src/Bundle/JoseFramework/Controller/JWKSetControllerFactory.php +++ b/src/Bundle/JoseFramework/Controller/JWKSetControllerFactory.php @@ -13,20 +13,13 @@ namespace Jose\Bundle\JoseFramework\Controller; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; class JWKSetControllerFactory { - private $jsonConverter; - - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function create(JWKSet $jwkset): JWKSetController { - return new JWKSetController($this->jsonConverter->encode($jwkset)); + return new JWKSetController(JsonConverter::encode($jwkset)); } } diff --git a/src/Bundle/JoseFramework/DependencyInjection/Source/Core/CoreSource.php b/src/Bundle/JoseFramework/DependencyInjection/Source/Core/CoreSource.php index fac42be4..8ac64595 100644 --- a/src/Bundle/JoseFramework/DependencyInjection/Source/Core/CoreSource.php +++ b/src/Bundle/JoseFramework/DependencyInjection/Source/Core/CoreSource.php @@ -16,8 +16,6 @@ use Jose\Bundle\JoseFramework\DataCollector\Collector; use Jose\Bundle\JoseFramework\DependencyInjection\Compiler; use Jose\Bundle\JoseFramework\DependencyInjection\Source\SourceWithCompilerPasses; -use Jose\Component\Core\Converter\JsonConverter; -use Jose\Component\Core\Converter\StandardConverter; use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -45,22 +43,10 @@ public function load(array $config, ContainerBuilder $container) $container->registerForAutoconfiguration(Collector::class)->addTag('jose.data_collector'); $loader->load('dev_services.php'); } - - $container->setAlias(JsonConverter::class, $config['json_converter']); - if (StandardConverter::class === $config['json_converter']) { - $loader->load('json_converter.php'); - } } public function getNodeDefinition(NodeDefinition $node) { - $node - ->children() - ->scalarNode('json_converter') - ->defaultValue(StandardConverter::class) - ->info('Converter used to encode and decode JSON objects (JWT payloads, keys, key sets...).') - ->end() - ->end(); } public function prepend(ContainerBuilder $container, array $config): array diff --git a/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php b/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php index f5f25064..c951de05 100644 --- a/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php +++ b/src/Bundle/JoseFramework/DependencyInjection/Source/KeyManagement/JWKSource.php @@ -23,7 +23,7 @@ class JWKSource implements Source { /** - * @var null|JWKSourceInterface[] + * @var JWKSourceInterface[]|null */ private $jwkSources = null; diff --git a/src/Bundle/JoseFramework/Resources/config/jku_source.php b/src/Bundle/JoseFramework/Resources/config/jku_source.php index 18c6fdfe..fee860fb 100644 --- a/src/Bundle/JoseFramework/Resources/config/jku_source.php +++ b/src/Bundle/JoseFramework/Resources/config/jku_source.php @@ -11,7 +11,6 @@ * of the MIT license. See the LICENSE file for details. */ -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\KeyManagement; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use function Symfony\Component\DependencyInjection\Loader\Configurator\ref; @@ -25,7 +24,6 @@ $container->set(KeyManagement\JKUFactory::class) ->public() ->args([ - ref(JsonConverter::class), ref('jose.http_client'), ref('jose.request_factory'), ]) @@ -34,7 +32,6 @@ $container->set(KeyManagement\X5UFactory::class) ->public() ->args([ - ref(JsonConverter::class), ref('jose.http_client'), ref('jose.request_factory'), ]) diff --git a/src/Bundle/JoseFramework/Resources/config/json_converter.php b/src/Bundle/JoseFramework/Resources/config/json_converter.php deleted file mode 100644 index eb4a724a..00000000 --- a/src/Bundle/JoseFramework/Resources/config/json_converter.php +++ /dev/null @@ -1,24 +0,0 @@ -services()->defaults() - ->private() - ->autoconfigure() - ->autowire(); - - $container->set(StandardConverter::class); -}; diff --git a/src/Bundle/JoseFramework/Services/JWEBuilder.php b/src/Bundle/JoseFramework/Services/JWEBuilder.php index 6ce141d2..04f22e42 100644 --- a/src/Bundle/JoseFramework/Services/JWEBuilder.php +++ b/src/Bundle/JoseFramework/Services/JWEBuilder.php @@ -16,7 +16,6 @@ use Jose\Bundle\JoseFramework\Event\Events; use Jose\Bundle\JoseFramework\Event\JWEBuiltSuccessEvent; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Encryption\Compression\CompressionMethodManager; use Jose\Component\Encryption\JWE; use Jose\Component\Encryption\JWEBuilder as BaseJWEBuilder; @@ -26,9 +25,9 @@ final class JWEBuilder extends BaseJWEBuilder { private $eventDispatcher; - public function __construct(JsonConverter $jsonConverter, AlgorithmManager $keyEncryptionAlgorithmManager, AlgorithmManager $contentEncryptionAlgorithmManager, CompressionMethodManager $compressionManager, EventDispatcherInterface $eventDispatcher) + public function __construct(AlgorithmManager $keyEncryptionAlgorithmManager, AlgorithmManager $contentEncryptionAlgorithmManager, CompressionMethodManager $compressionManager, EventDispatcherInterface $eventDispatcher) { - parent::__construct($jsonConverter, $keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); + parent::__construct($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionManager); $this->eventDispatcher = $eventDispatcher; } diff --git a/src/Bundle/JoseFramework/Services/JWEBuilderFactory.php b/src/Bundle/JoseFramework/Services/JWEBuilderFactory.php index 128467c1..a77860cf 100644 --- a/src/Bundle/JoseFramework/Services/JWEBuilderFactory.php +++ b/src/Bundle/JoseFramework/Services/JWEBuilderFactory.php @@ -14,20 +14,17 @@ namespace Jose\Bundle\JoseFramework\Services; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Encryption\Compression\CompressionMethodManagerFactory; use Symfony\Component\EventDispatcher\EventDispatcherInterface; final class JWEBuilderFactory { private $eventDispatcher; - private $jsonEncoder; private $algorithmManagerFactory; private $compressionMethodManagerFactory; - public function __construct(JsonConverter $jsonEncoder, AlgorithmManagerFactory $algorithmManagerFactory, CompressionMethodManagerFactory $compressionMethodManagerFactory, EventDispatcherInterface $eventDispatcher) + public function __construct(AlgorithmManagerFactory $algorithmManagerFactory, CompressionMethodManagerFactory $compressionMethodManagerFactory, EventDispatcherInterface $eventDispatcher) { - $this->jsonEncoder = $jsonEncoder; $this->eventDispatcher = $eventDispatcher; $this->algorithmManagerFactory = $algorithmManagerFactory; $this->compressionMethodManagerFactory = $compressionMethodManagerFactory; @@ -46,6 +43,6 @@ public function create(array $keyEncryptionAlgorithms, array $contentEncryptionA $contentEncryptionAlgorithmManager = $this->algorithmManagerFactory->create($contentEncryptionAlgorithm); $compressionMethodManager = $this->compressionMethodManagerFactory->create($compressionMethods); - return new JWEBuilder($this->jsonEncoder, $keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionMethodManager, $this->eventDispatcher); + return new JWEBuilder($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionMethodManager, $this->eventDispatcher); } } diff --git a/src/Bundle/JoseFramework/Services/JWSBuilder.php b/src/Bundle/JoseFramework/Services/JWSBuilder.php index 721652e4..76fbd1af 100644 --- a/src/Bundle/JoseFramework/Services/JWSBuilder.php +++ b/src/Bundle/JoseFramework/Services/JWSBuilder.php @@ -16,7 +16,6 @@ use Jose\Bundle\JoseFramework\Event\Events; use Jose\Bundle\JoseFramework\Event\JWSBuiltSuccessEvent; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Signature\JWS; use Jose\Component\Signature\JWSBuilder as BaseJWSBuilder; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -25,9 +24,9 @@ final class JWSBuilder extends BaseJWSBuilder { private $eventDispatcher; - public function __construct(JsonConverter $jsonConverter, AlgorithmManager $signatureAlgorithmManager, EventDispatcherInterface $eventDispatcher) + public function __construct(AlgorithmManager $signatureAlgorithmManager, EventDispatcherInterface $eventDispatcher) { - parent::__construct($jsonConverter, $signatureAlgorithmManager); + parent::__construct($signatureAlgorithmManager); $this->eventDispatcher = $eventDispatcher; } diff --git a/src/Bundle/JoseFramework/Services/JWSBuilderFactory.php b/src/Bundle/JoseFramework/Services/JWSBuilderFactory.php index fa1ea9a1..32fda50f 100644 --- a/src/Bundle/JoseFramework/Services/JWSBuilderFactory.php +++ b/src/Bundle/JoseFramework/Services/JWSBuilderFactory.php @@ -14,20 +14,16 @@ namespace Jose\Bundle\JoseFramework\Services; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\JsonConverter; use Symfony\Component\EventDispatcher\EventDispatcherInterface; final class JWSBuilderFactory { private $eventDispatcher; - private $jsonEncoder; - private $signatureAlgorithmManagerFactory; - public function __construct(JsonConverter $jsonEncoder, AlgorithmManagerFactory $signatureAlgorithmManagerFactory, EventDispatcherInterface $eventDispatcher) + public function __construct(AlgorithmManagerFactory $signatureAlgorithmManagerFactory, EventDispatcherInterface $eventDispatcher) { - $this->jsonEncoder = $jsonEncoder; $this->signatureAlgorithmManagerFactory = $signatureAlgorithmManagerFactory; $this->eventDispatcher = $eventDispatcher; } @@ -41,6 +37,6 @@ public function create(array $algorithms): JWSBuilder { $algorithmManager = $this->signatureAlgorithmManagerFactory->create($algorithms); - return new JWSBuilder($this->jsonEncoder, $algorithmManager, $this->eventDispatcher); + return new JWSBuilder($algorithmManager, $this->eventDispatcher); } } diff --git a/src/Bundle/JoseFramework/Tests/Functional/Encryption/JWEComputationTest.php b/src/Bundle/JoseFramework/Tests/Functional/Encryption/JWEComputationTest.php index aa4e46a7..a6823030 100644 --- a/src/Bundle/JoseFramework/Tests/Functional/Encryption/JWEComputationTest.php +++ b/src/Bundle/JoseFramework/Tests/Functional/Encryption/JWEComputationTest.php @@ -13,7 +13,6 @@ namespace Jose\Bundle\JoseFramework\Tests\Functional\Encryption; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Encryption\JWEBuilder; use Jose\Component\Encryption\JWEBuilderFactory; @@ -53,7 +52,7 @@ public function iCanCreateAndLoadAToken() /** @var JWEDecrypter $loader */ $loader = $container->get('jose.jwe_decrypter.loader1'); - $serializer = new CompactSerializer(new StandardConverter()); + $serializer = new CompactSerializer(); $jwe = $builder ->create() diff --git a/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWEEncoderTest.php b/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWEEncoderTest.php index 0e05076d..70cb9350 100644 --- a/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWEEncoderTest.php +++ b/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWEEncoderTest.php @@ -16,7 +16,6 @@ use Jose\Bundle\JoseFramework\Serializer\JWEEncoder; use Jose\Bundle\JoseFramework\Services\JWEBuilderFactory; use Jose\Bundle\JoseFramework\Services\JWELoaderFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Encryption\JWE; use Jose\Component\Encryption\JWEBuilderFactory as BaseJWEBuilderFactory; @@ -204,7 +203,7 @@ public function jWEEncoderSupportsCustomSerializerManager() $client = static::createClient(); $container = $client->getContainer(); $jweSerializerManager = new JWESerializerManager([ - new CompactSerializer(new StandardConverter()), + new CompactSerializer(), ]); $serializer = new JWEEncoder($container->get(JWESerializerManagerFactory::class), $jweSerializerManager); /** @var JWEBuilderFactory $jweFactory */ @@ -242,7 +241,7 @@ public function jWEEncoderShouldThrowOnUnsupportedFormatWhenEncoding() $client = static::createClient(); $container = $client->getContainer(); $jweSerializerManager = new JWESerializerManager([ - new CompactSerializer(new StandardConverter()), + new CompactSerializer(), ]); $serializer = new JWEEncoder($container->get(JWESerializerManagerFactory::class), $jweSerializerManager); /** @var JWEBuilderFactory $jweFactory */ @@ -275,7 +274,7 @@ public function jWEEncoderShouldThrowOnUnsupportedFormatWhenDecoding() $client = static::createClient(); $container = $client->getContainer(); $jweSerializerManager = new JWESerializerManager([ - new CompactSerializer(new StandardConverter()), + new CompactSerializer(), ]); $serializer = new JWEEncoder($container->get(JWESerializerManagerFactory::class), $jweSerializerManager); /** @var JWEBuilderFactory $jweFactory */ diff --git a/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWSEncoderTest.php b/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWSEncoderTest.php index b5a50b95..286b898c 100644 --- a/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWSEncoderTest.php +++ b/src/Bundle/JoseFramework/Tests/Functional/Serializer/JWSEncoderTest.php @@ -15,7 +15,6 @@ use Jose\Bundle\JoseFramework\Serializer\JWSEncoder; use Jose\Bundle\JoseFramework\Services\JWSBuilderFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\JWS; use Jose\Component\Signature\JWSBuilderFactory as BaseJWSBuilderFactory; @@ -188,7 +187,7 @@ public function jWSEncoderSupportsCustomSerializerManager() $client = static::createClient(); $container = $client->getContainer(); $jwsSerializerManager = new JWSSerializerManager([ - new CompactSerializer(new StandardConverter()), + new CompactSerializer(), ]); $serializer = new JWSEncoder($container->get(JWSSerializerManagerFactory::class), $jwsSerializerManager); /** @var JWSBuilderFactory $jwsFactory */ @@ -224,7 +223,7 @@ public function jWSEncoderShouldThrowOnUnsupportedFormatWhenEncoding() $client = static::createClient(); $container = $client->getContainer(); $serializerManager = new JWSSerializerManager([ - new CompactSerializer(new StandardConverter()), + new CompactSerializer(), ]); $serializer = new JWSEncoder($container->get(JWSSerializerManagerFactory::class), $serializerManager); /** @var JWSBuilderFactory $jwsFactory */ @@ -255,7 +254,7 @@ public function jWSEncoderShouldThrowOnUnsupportedFormatWhenDecoding() $client = static::createClient(); $container = $client->getContainer(); $serializerManager = new JWSSerializerManager([ - new CompactSerializer(new StandardConverter()), + new CompactSerializer(), ]); $serializer = new JWSEncoder($container->get(JWSSerializerManagerFactory::class), $serializerManager); /** @var JWSBuilderFactory $jwsFactory */ diff --git a/src/Bundle/JoseFramework/Tests/Functional/Signature/JWSComputationTest.php b/src/Bundle/JoseFramework/Tests/Functional/Signature/JWSComputationTest.php index 5f860038..59a45abc 100644 --- a/src/Bundle/JoseFramework/Tests/Functional/Signature/JWSComputationTest.php +++ b/src/Bundle/JoseFramework/Tests/Functional/Signature/JWSComputationTest.php @@ -13,7 +13,6 @@ namespace Jose\Bundle\JoseFramework\Tests\Functional\Signature; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\JWSBuilder; use Jose\Component\Signature\JWSBuilderFactory; @@ -53,7 +52,7 @@ public function createAndLoadAToken() /** @var JWSVerifier $loader */ $loader = $container->get('jose.jws_verifier.loader1'); - $serializer = new CompactSerializer(new StandardConverter()); + $serializer = new CompactSerializer(); $jws = $builder ->create() diff --git a/src/Bundle/JoseFramework/Tests/TestBundle/Converter/CustomJsonConverter.php b/src/Bundle/JoseFramework/Tests/TestBundle/Converter/CustomJsonConverter.php deleted file mode 100644 index 1b4fcf97..00000000 --- a/src/Bundle/JoseFramework/Tests/TestBundle/Converter/CustomJsonConverter.php +++ /dev/null @@ -1,45 +0,0 @@ -options = JSON_UNESCAPED_UNICODE; - } - - public function encode($payload): string - { - return \json_encode($payload, $this->options, 512); - } - - public function decode(string $payload, bool $associativeArray = true) - { - return \json_decode($payload, $associativeArray, 512, $this->options); - } -} diff --git a/src/Bundle/JoseFramework/Tests/config/config_test.yml b/src/Bundle/JoseFramework/Tests/config/config_test.yml index 86af2a28..3f3b0c8a 100644 --- a/src/Bundle/JoseFramework/Tests/config/config_test.yml +++ b/src/Bundle/JoseFramework/Tests/config/config_test.yml @@ -20,7 +20,6 @@ services: Jose\Bundle\JoseFramework\Tests\TestBundle\MessageFactory: ~ jose: - json_converter: 'Jose\Bundle\JoseFramework\Tests\TestBundle\Converter\CustomJsonConverter' jku_factory: enabled: true client: 'httplug.client.mock' diff --git a/src/Component/Console/AddKeyIntoKeysetCommand.php b/src/Component/Console/AddKeyIntoKeysetCommand.php index 276836e3..a7411d71 100644 --- a/src/Component/Console/AddKeyIntoKeysetCommand.php +++ b/src/Component/Console/AddKeyIntoKeysetCommand.php @@ -13,20 +13,15 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class AddKeyIntoKeysetCommand extends ObjectOutputCommand { - public function __construct(JsonConverter $jsonConverter, ?string $name = null) - { - parent::__construct($jsonConverter, $name); - } - protected function configure() { parent::configure(); @@ -49,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getKeyset(InputInterface $input): JWKSet { $jwkset = $input->getArgument('jwkset'); - $json = $this->jsonConverter->decode($jwkset); + $json = JsonConverter::decode($jwkset); if (\is_array($json)) { return JWKSet::createFromKeyData($json); } @@ -60,7 +55,7 @@ private function getKeyset(InputInterface $input): JWKSet private function getKey(InputInterface $input): JWK { $jwkset = $input->getArgument('jwk'); - $json = $this->jsonConverter->decode($jwkset); + $json = JsonConverter::decode($jwkset); if (\is_array($json)) { return JWK::create($json); } diff --git a/src/Component/Console/GetThumbprintCommand.php b/src/Component/Console/GetThumbprintCommand.php index 492339ed..b403cb25 100644 --- a/src/Component/Console/GetThumbprintCommand.php +++ b/src/Component/Console/GetThumbprintCommand.php @@ -14,6 +14,7 @@ namespace Jose\Component\Console; use Jose\Component\Core\JWK; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -35,7 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $jwk = $input->getArgument('jwk'); $hash = $input->getOption('hash'); - $json = $this->jsonConverter->decode($jwk); + $json = JsonConverter::decode($jwk); if (!\is_array($json)) { throw new \InvalidArgumentException('Invalid input.'); } diff --git a/src/Component/Console/JKULoaderCommand.php b/src/Component/Console/JKULoaderCommand.php index 77df255d..e6e99173 100644 --- a/src/Component/Console/JKULoaderCommand.php +++ b/src/Component/Console/JKULoaderCommand.php @@ -13,7 +13,6 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\KeyManagement\JKUFactory; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -23,10 +22,10 @@ final class JKULoaderCommand extends ObjectOutputCommand { private $jkuFactory; - public function __construct(JKUFactory $jkuFactory, JsonConverter $jsonConverter, ?string $name = null) + public function __construct(JKUFactory $jkuFactory, ?string $name = null) { $this->jkuFactory = $jkuFactory; - parent::__construct($jsonConverter, $name); + parent::__construct($name); } protected function configure() diff --git a/src/Component/Console/KeyAnalyzerCommand.php b/src/Component/Console/KeyAnalyzerCommand.php index 17251a5f..3d4dd362 100644 --- a/src/Component/Console/KeyAnalyzerCommand.php +++ b/src/Component/Console/KeyAnalyzerCommand.php @@ -13,8 +13,8 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWK; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\KeyManagement\Analyzer\KeyAnalyzerManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Formatter\OutputFormatterStyle; @@ -26,13 +26,10 @@ final class KeyAnalyzerCommand extends Command { private $analyzerManager; - private $jsonConverter; - - public function __construct(KeyAnalyzerManager $analyzerManager, JsonConverter $jsonConverter, string $name = null) + public function __construct(KeyAnalyzerManager $analyzerManager, string $name = null) { parent::__construct($name); $this->analyzerManager = $analyzerManager; - $this->jsonConverter = $jsonConverter; } protected function configure() @@ -66,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getKey(InputInterface $input): JWK { $jwk = $input->getArgument('jwk'); - $json = $this->jsonConverter->decode($jwk); + $json = JsonConverter::decode($jwk); if (\is_array($json)) { return JWK::create($json); } diff --git a/src/Component/Console/KeysetAnalyzerCommand.php b/src/Component/Console/KeysetAnalyzerCommand.php index fe2e6bbe..71455f09 100644 --- a/src/Component/Console/KeysetAnalyzerCommand.php +++ b/src/Component/Console/KeysetAnalyzerCommand.php @@ -13,8 +13,8 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\KeyManagement\Analyzer\KeyAnalyzerManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Formatter\OutputFormatterStyle; @@ -26,13 +26,10 @@ final class KeysetAnalyzerCommand extends Command { private $analyzerManager; - private $jsonConverter; - - public function __construct(KeyAnalyzerManager $analyzerManager, JsonConverter $jsonConverter, string $name = null) + public function __construct(KeyAnalyzerManager $analyzerManager, string $name = null) { parent::__construct($name); $this->analyzerManager = $analyzerManager; - $this->jsonConverter = $jsonConverter; } protected function configure() @@ -105,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getKeyset(InputInterface $input): JWKSet { $jwkset = $input->getArgument('jwkset'); - $json = $this->jsonConverter->decode($jwkset); + $json = JsonConverter::decode($jwkset); if (\is_array($json)) { return JWKSet::createFromKeyData($json); } diff --git a/src/Component/Console/MergeKeysetCommand.php b/src/Component/Console/MergeKeysetCommand.php index 6b443d9a..90e59c62 100644 --- a/src/Component/Console/MergeKeysetCommand.php +++ b/src/Component/Console/MergeKeysetCommand.php @@ -13,19 +13,14 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class MergeKeysetCommand extends ObjectOutputCommand { - public function __construct(JsonConverter $jsonConverter, ?string $name = null) - { - parent::__construct($jsonConverter, $name); - } - protected function configure() { parent::configure(); @@ -41,7 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $keySets = $input->getArgument('jwksets'); $newJwkset = JWKSet::createFromKeys([]); foreach ($keySets as $keySet) { - $json = $this->jsonConverter->decode($keySet); + $json = JsonConverter::decode($keySet); if (!\is_array($json)) { throw new \InvalidArgumentException('The argument must be a valid JWKSet.'); } diff --git a/src/Component/Console/ObjectOutputCommand.php b/src/Component/Console/ObjectOutputCommand.php index 538c6739..a136b1b8 100644 --- a/src/Component/Console/ObjectOutputCommand.php +++ b/src/Component/Console/ObjectOutputCommand.php @@ -13,24 +13,16 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; abstract class ObjectOutputCommand extends Command { - protected $jsonConverter; - - public function __construct(JsonConverter $jsonConverter, ?string $name = null) - { - $this->jsonConverter = $jsonConverter; - parent::__construct($name); - } - protected function prepareJsonOutput(InputInterface $input, OutputInterface $output, \JsonSerializable $json): void { - $data = $this->jsonConverter->encode($json); + $data = JsonConverter::encode($json); $output->write($data); } } diff --git a/src/Component/Console/OptimizeRsaKeyCommand.php b/src/Component/Console/OptimizeRsaKeyCommand.php index 90348134..05551705 100644 --- a/src/Component/Console/OptimizeRsaKeyCommand.php +++ b/src/Component/Console/OptimizeRsaKeyCommand.php @@ -14,6 +14,7 @@ namespace Jose\Component\Console; use Jose\Component\Core\JWK; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\KeyManagement\KeyConverter\RSAKey; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -33,7 +34,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $jwk = $input->getArgument('jwk'); - $json = $this->jsonConverter->decode($jwk); + $json = JsonConverter::decode($jwk); if (!\is_array($json)) { throw new \InvalidArgumentException('Invalid input.'); } diff --git a/src/Component/Console/PemConverterCommand.php b/src/Component/Console/PemConverterCommand.php index cfc96771..a5ba8daa 100644 --- a/src/Component/Console/PemConverterCommand.php +++ b/src/Component/Console/PemConverterCommand.php @@ -15,6 +15,7 @@ use Jose\Component\Core\JWK; use Jose\Component\Core\Util\ECKey; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Core\Util\RSAKey; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -34,7 +35,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $jwk = $input->getArgument('jwk'); - $json = $this->jsonConverter->decode($jwk); + $json = JsonConverter::decode($jwk); if (!\is_array($json)) { throw new \InvalidArgumentException('Invalid key.'); } diff --git a/src/Component/Console/PublicKeyCommand.php b/src/Component/Console/PublicKeyCommand.php index f62dd6ce..6eae966a 100644 --- a/src/Component/Console/PublicKeyCommand.php +++ b/src/Component/Console/PublicKeyCommand.php @@ -13,19 +13,14 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWK; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class PublicKeyCommand extends ObjectOutputCommand { - public function __construct(JsonConverter $jsonConverter, ?string $name = null) - { - parent::__construct($jsonConverter, $name); - } - protected function configure() { parent::configure(); @@ -47,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getKey(InputInterface $input): JWK { $jwk = $input->getArgument('jwk'); - $json = $this->jsonConverter->decode($jwk); + $json = JsonConverter::decode($jwk); if (\is_array($json)) { return JWK::create($json); } diff --git a/src/Component/Console/PublicKeysetCommand.php b/src/Component/Console/PublicKeysetCommand.php index b0b2463d..048ad446 100644 --- a/src/Component/Console/PublicKeysetCommand.php +++ b/src/Component/Console/PublicKeysetCommand.php @@ -13,19 +13,14 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class PublicKeysetCommand extends ObjectOutputCommand { - public function __construct(JsonConverter $jsonConverter, ?string $name = null) - { - parent::__construct($jsonConverter, $name); - } - protected function configure() { parent::configure(); @@ -50,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getKeyset(InputInterface $input): JWKSet { $jwkset = $input->getArgument('jwkset'); - $json = $this->jsonConverter->decode($jwkset); + $json = JsonConverter::decode($jwkset); if (\is_array($json)) { return JWKSet::createFromKeyData($json); } diff --git a/src/Component/Console/RotateKeysetCommand.php b/src/Component/Console/RotateKeysetCommand.php index 6817a9ef..c474e398 100644 --- a/src/Component/Console/RotateKeysetCommand.php +++ b/src/Component/Console/RotateKeysetCommand.php @@ -13,20 +13,15 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; final class RotateKeysetCommand extends ObjectOutputCommand { - public function __construct(JsonConverter $jsonConverter, ?string $name = null) - { - parent::__construct($jsonConverter, $name); - } - protected function configure() { parent::configure(); @@ -54,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output) private function getKeyset(InputInterface $input): JWKSet { $jwkset = $input->getArgument('jwkset'); - $json = $this->jsonConverter->decode($jwkset); + $json = JsonConverter::decode($jwkset); if (\is_array($json)) { return JWKSet::createFromKeyData($json); } @@ -65,7 +60,7 @@ private function getKeyset(InputInterface $input): JWKSet private function getKey(InputInterface $input): JWK { $jwkset = $input->getArgument('jwk'); - $json = $this->jsonConverter->decode($jwkset); + $json = JsonConverter::decode($jwkset); if (\is_array($json)) { return JWK::create($json); } diff --git a/src/Component/Console/Tests/AnalyzeCommandTest.php b/src/Component/Console/Tests/AnalyzeCommandTest.php index d431beff..885ec23c 100644 --- a/src/Component/Console/Tests/AnalyzeCommandTest.php +++ b/src/Component/Console/Tests/AnalyzeCommandTest.php @@ -14,9 +14,9 @@ namespace Jose\Component\Console\Tests; use Jose\Component\Console; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\KeyManagement\Analyzer; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; @@ -38,12 +38,12 @@ public function iCanAnalyzeAKeyAndGetInformation() 'n' => '0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqbw0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw', 'e' => 'AQAB', ]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwk' => $converter->encode($jwk), + 'jwk' => JsonConverter::encode($jwk), ]); $output = new BufferedOutput(); - $command = new Console\KeyAnalyzerCommand($this->getKeyAnalyzer(), $converter); + $command = new Console\KeyAnalyzerCommand($this->getKeyAnalyzer()); $command->run($input, $output); $content = $output->fetch(); static::assertContains('* The parameter "alg" should be added.', $content); @@ -70,12 +70,12 @@ public function iCanAnalyzeAKeySetAndGetInformation() 'y' => 'ADSmRA43Z1DSNx_RvcLI87cdL07l6jQyyBXMoxVg_l2Th-x3S1WDhjDly79ajL4Kkd0AZMaZmh9ubmf63e3kyMj2', ], ]]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwkset' => $converter->encode($keyset), + 'jwkset' => JsonConverter::encode($keyset), ]); $output = new BufferedOutput(); - $command = new Console\KeysetAnalyzerCommand($this->getKeyAnalyzer(), $converter); + $command = new Console\KeysetAnalyzerCommand($this->getKeyAnalyzer()); $command->run($input, $output); $content = $output->fetch(); static::assertContains('Analysing key with index/kid "1"', $content); diff --git a/src/Component/Console/Tests/KeyConversionCommandTest.php b/src/Component/Console/Tests/KeyConversionCommandTest.php index 4ee00ed0..f2525aa5 100644 --- a/src/Component/Console/Tests/KeyConversionCommandTest.php +++ b/src/Component/Console/Tests/KeyConversionCommandTest.php @@ -14,9 +14,9 @@ namespace Jose\Component\Console\Tests; use Jose\Component\Console; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; @@ -32,12 +32,11 @@ class KeyConversionCommandTest extends TestCase */ public function iCanLoadAKeyFile() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'file' => __DIR__.'/Sample/2048b-rsa-example-cert.pem', ]); $output = new BufferedOutput(); - $command = new Console\KeyFileLoaderCommand($converter); + $command = new Console\KeyFileLoaderCommand(); $command->run($input, $output); $content = $output->fetch(); $jwk = JWK::createFromJson($content); @@ -49,13 +48,12 @@ public function iCanLoadAKeyFile() */ public function iCanLoadAnEncryptedKeyFile() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'file' => __DIR__.'/Sample/private.es512.encrypted.key', '--secret' => 'test', ]); $output = new BufferedOutput(); - $command = new Console\KeyFileLoaderCommand($converter); + $command = new Console\KeyFileLoaderCommand(); $command->run($input, $output); $content = $output->fetch(); $jwk = JWK::createFromJson($content); @@ -67,13 +65,12 @@ public function iCanLoadAnEncryptedKeyFile() */ public function iCanLoadAPKCS12CertificateFile() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'file' => __DIR__.'/Sample/CertRSA.p12', '--secret' => 'certRSA', ]); $output = new BufferedOutput(); - $command = new Console\P12CertificateLoaderCommand($converter); + $command = new Console\P12CertificateLoaderCommand(); $command->run($input, $output); $content = $output->fetch(); $jwk = JWK::createFromJson($content); @@ -85,12 +82,11 @@ public function iCanLoadAPKCS12CertificateFile() */ public function iCanLoadAX509CertificateFile() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'file' => __DIR__.'/Sample/google.crt', ]); $output = new BufferedOutput(); - $command = new Console\X509CertificateLoaderCommand($converter); + $command = new Console\X509CertificateLoaderCommand(); $command->run($input, $output); $content = $output->fetch(); $jwk = JWK::createFromJson($content); @@ -108,12 +104,12 @@ public function iCanOptimizeARsaKey() 'e' => 'AQAB', 'd' => 'JSqz6ijkk3dfdSEA_0iMT_1HeIJ1ft4msZ6qw7_1JSCGQAALeZ1yM0QHO3uX-Jr7HC7v1rGVcwsonAhei2qu3rk-w_iCnRL6QkkMNBnDQycwaWpwGsMBFF-UqstOJNggE4AHX-aDnbd4wbKVvdX7ieehPngbPkHcJFdg_iSZCQNoajz6XfEruyIi7_IFXYEGmH_UyEbQkgNtriZysutgYdolUjo9flUlh20HbuV3NwsPjGyDG4dUMpNpdBpSuRHYKLX6h3FjeLhItBmhBfuL7d-G3EXwKlwfNXXYivqY5NQAkFNrRbvFlc_ARIws3zAfykPDIWGWFiPiN3H-hXMgAQ', ]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwk' => $converter->encode($jwk), + 'jwk' => JsonConverter::encode($jwk), ]); $output = new BufferedOutput(); - $command = new Console\OptimizeRsaKeyCommand($converter); + $command = new Console\OptimizeRsaKeyCommand(); $command->run($input, $output); $content = $output->fetch(); $jwk = JWK::createFromJson($content); @@ -141,12 +137,12 @@ public function iCanConvertARsaKeyIntoPKCS1() 'dq' => 'rNTcNPFLhj_hPnq4UzliZt94RaipB7mzGldr1nuMnqeBotmOsrHeI7S0F_C7VSLWgjwKrnSwZIQbRRGAOCNZWva4ZiMu-LbnOTAMB4TkU7vrY9Kh6QnAv47Q5t1YGBN1CLUdA3u6zHcocvtudXTJGgAqL1AsaLEvBMVH8zFIEQE', 'qi' => 'bbFp1zSfnmmOUYUtbaKhmFofn0muf1PrnMGq6zeu8zruf3gK9Y1oDsUk54FlV0mNBO3_t3Zbw2752CLklt73zesVeF-Nsc1kDnx_WGf4YrQpLh5PvkEfT_wPbveKTTcVXiVxMPHHZ-n2kOe3oyShycSLP5_I_SYN-loZHu7QC_I', ]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwk' => $converter->encode($jwk), + 'jwk' => JsonConverter::encode($jwk), ]); $output = new BufferedOutput(); - $command = new Console\PemConverterCommand($converter); + $command = new Console\PemConverterCommand(); $command->run($input, $output); $content = $output->fetch(); static::assertContains('-----BEGIN RSA PRIVATE KEY-----', $content); @@ -164,12 +160,12 @@ public function iCanConvertAnEcKeyIntoPKCS1() 'x' => 'YcIMUkalwbeeAVkUF6FP3aBVlCzlqxEd7i0uN_4roA0', 'y' => 'bU8wOWJBkTNZ61gB1_4xp-r8-uVsQB8D6Xsl-aKMCy8', ]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwk' => $converter->encode($jwk), + 'jwk' => JsonConverter::encode($jwk), ]); $output = new BufferedOutput(); - $command = new Console\PemConverterCommand($converter); + $command = new Console\PemConverterCommand(); $command->run($input, $output); $content = $output->fetch(); static::assertContains('-----BEGIN EC PRIVATE KEY-----', $content); @@ -187,12 +183,12 @@ public function iCanConvertAPrivateKeyIntoPublicKey() 'x' => 'YcIMUkalwbeeAVkUF6FP3aBVlCzlqxEd7i0uN_4roA0', 'y' => 'bU8wOWJBkTNZ61gB1_4xp-r8-uVsQB8D6Xsl-aKMCy8', ]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwk' => $converter->encode($jwk), + 'jwk' => JsonConverter::encode($jwk), ]); $output = new BufferedOutput(); - $command = new Console\PublicKeyCommand($converter); + $command = new Console\PublicKeyCommand(); $command->run($input, $output); $content = $output->fetch(); static::assertContains('{"kty":"EC","crv":"P-256","x":"YcIMUkalwbeeAVkUF6FP3aBVlCzlqxEd7i0uN_4roA0","y":"bU8wOWJBkTNZ61gB1_4xp-r8-uVsQB8D6Xsl-aKMCy8"}', $content); @@ -217,12 +213,12 @@ public function iCanConvertPrivateKeysIntoPublicKeys() 'y' => 'ADSmRA43Z1DSNx_RvcLI87cdL07l6jQyyBXMoxVg_l2Th-x3S1WDhjDly79ajL4Kkd0AZMaZmh9ubmf63e3kyMj2', ], ]]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwkset' => $converter->encode($keyset), + 'jwkset' => JsonConverter::encode($keyset), ]); $output = new BufferedOutput(); - $command = new Console\PublicKeysetCommand($converter); + $command = new Console\PublicKeysetCommand(); $command->run($input, $output); $content = $output->fetch(); static::assertContains('{"keys":[{"kty":"EC","crv":"P-256","x":"f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU","y":"x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0"},{"kty":"EC","crv":"P-521","x":"AekpBQ8ST8a8VcfVOTNl353vSrDCLLJXmPk06wTjxrrjcBpXp5EOnYG_NjFZ6OvLFV1jSfS9tsz4qUxcWceqwQGk","y":"ADSmRA43Z1DSNx_RvcLI87cdL07l6jQyyBXMoxVg_l2Th-x3S1WDhjDly79ajL4Kkd0AZMaZmh9ubmf63e3kyMj2"}]}', $content); @@ -240,12 +236,12 @@ public function iCanGetTheThumbprintOfAKey() 'alg' => 'RS256', 'kid' => '2011-04-29', ]); - $converter = new StandardConverter(); + $input = new ArrayInput([ - 'jwk' => $converter->encode($jwk), + 'jwk' => JsonConverter::encode($jwk), ]); $output = new BufferedOutput(); - $command = new Console\GetThumbprintCommand($converter); + $command = new Console\GetThumbprintCommand(); $command->run($input, $output); $content = $output->fetch(); static::assertEquals('NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs', $content); diff --git a/src/Component/Console/Tests/KeyCreationCommandTest.php b/src/Component/Console/Tests/KeyCreationCommandTest.php index 05406247..6d43fc56 100644 --- a/src/Component/Console/Tests/KeyCreationCommandTest.php +++ b/src/Component/Console/Tests/KeyCreationCommandTest.php @@ -15,7 +15,6 @@ use Base64Url\Base64Url; use Jose\Component\Console; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; @@ -32,8 +31,7 @@ class KeyCreationCommandTest extends TestCase */ public function theEllipticCurveKeyCreationCommandIsAvailable() { - $converter = new StandardConverter(); - $command = new Console\EcKeyGeneratorCommand($converter); + $command = new Console\EcKeyGeneratorCommand(); static::assertTrue($command->isEnabled()); } @@ -45,10 +43,9 @@ public function theEllipticCurveKeyCreationCommandIsAvailable() */ public function theEllipticCurveKeyCreationCommandNeedTheCurveArgument() { - $converter = new StandardConverter(); $input = new ArrayInput([]); $output = new BufferedOutput(); - $command = new Console\EcKeyGeneratorCommand($converter); + $command = new Console\EcKeyGeneratorCommand(); $command->run($input, $output); } @@ -60,12 +57,11 @@ public function theEllipticCurveKeyCreationCommandNeedTheCurveArgument() */ public function iCannotCreateAnEllipticCurveKeyWithAnUnsupportedCurve() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'curve' => 'P-128', ]); $output = new BufferedOutput(); - $command = new Console\EcKeyGeneratorCommand($converter); + $command = new Console\EcKeyGeneratorCommand(); $command->run($input, $output); } @@ -75,13 +71,12 @@ public function iCannotCreateAnEllipticCurveKeyWithAnUnsupportedCurve() */ public function iCanCreateAnEllipticCurveKeyWithCurveP256() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'curve' => 'P-256', '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\EcKeyGeneratorCommand($converter); + $command = new Console\EcKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -96,11 +91,10 @@ public function iCanCreateAnEllipticCurveKeyWithCurveP256() */ public function iCannotCreateAnOctetKeyWithoutKeySize() { - $converter = new StandardConverter(); $input = new ArrayInput([ ]); $output = new BufferedOutput(); - $command = new Console\OctKeyGeneratorCommand($converter); + $command = new Console\OctKeyGeneratorCommand(); $command->run($input, $output); } @@ -110,13 +104,12 @@ public function iCannotCreateAnOctetKeyWithoutKeySize() */ public function iCanCreateAnOctetKey() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'size' => 256, '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\OctKeyGeneratorCommand($converter); + $command = new Console\OctKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -129,12 +122,11 @@ public function iCanCreateAnOctetKey() */ public function iCanCreateAnOctetKeyUsingASecret() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'secret' => 'This is my secret', ]); $output = new BufferedOutput(); - $command = new Console\SecretKeyGeneratorCommand($converter); + $command = new Console\SecretKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -150,13 +142,13 @@ public function iCanCreateAnOctetKeyUsingASecret() public function iCanCreateAnOctetKeyUsingABinarySecret() { $secret = \random_bytes(20); - $converter = new StandardConverter(); + $input = new ArrayInput([ 'secret' => $secret, '--is_b64', ]); $output = new BufferedOutput(); - $command = new Console\SecretKeyGeneratorCommand($converter); + $command = new Console\SecretKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -173,11 +165,10 @@ public function iCanCreateAnOctetKeyUsingABinarySecret() */ public function iCannotCreateAnOctetKeyPairWithoutKeyCurve() { - $converter = new StandardConverter(); $input = new ArrayInput([ ]); $output = new BufferedOutput(); - $command = new Console\OkpKeyGeneratorCommand($converter); + $command = new Console\OkpKeyGeneratorCommand(); $command->run($input, $output); } @@ -187,13 +178,12 @@ public function iCannotCreateAnOctetKeyPairWithoutKeyCurve() */ public function iCanCreateAnOctetKeyPair() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'curve' => 'X25519', '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\OkpKeyGeneratorCommand($converter); + $command = new Console\OkpKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -206,12 +196,11 @@ public function iCanCreateAnOctetKeyPair() */ public function iCanCreateANoneKey() { - $converter = new StandardConverter(); $input = new ArrayInput([ '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\NoneKeyGeneratorCommand($converter); + $command = new Console\NoneKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -226,11 +215,10 @@ public function iCanCreateANoneKey() */ public function iCannotCreateAnRsaKeyWithoutKeySize() { - $converter = new StandardConverter(); $input = new ArrayInput([ ]); $output = new BufferedOutput(); - $command = new Console\RsaKeyGeneratorCommand($converter); + $command = new Console\RsaKeyGeneratorCommand(); $command->run($input, $output); } @@ -240,13 +228,12 @@ public function iCannotCreateAnRsaKeyWithoutKeySize() */ public function iCanCreateAnRsaKey() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'size' => 1024, '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\RsaKeyGeneratorCommand($converter); + $command = new Console\RsaKeyGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); diff --git a/src/Component/Console/Tests/KeySetCreationCommandTest.php b/src/Component/Console/Tests/KeySetCreationCommandTest.php index 1d3be540..00a11dd1 100644 --- a/src/Component/Console/Tests/KeySetCreationCommandTest.php +++ b/src/Component/Console/Tests/KeySetCreationCommandTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Console\Tests; use Jose\Component\Console; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWKSet; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\ArrayInput; @@ -31,8 +30,7 @@ class KeySetCreationCommandTest extends TestCase */ public function theEllipticCurveKeySetCreationCommandIsAvailable() { - $converter = new StandardConverter(); - $command = new Console\EcKeysetGeneratorCommand($converter); + $command = new Console\EcKeysetGeneratorCommand(); static::assertTrue($command->isEnabled()); } @@ -44,10 +42,9 @@ public function theEllipticCurveKeySetCreationCommandIsAvailable() */ public function theEllipticCurveKeySetCreationCommandNeedTheCurveAndQuantityArguments() { - $converter = new StandardConverter(); $input = new ArrayInput([]); $output = new BufferedOutput(); - $command = new Console\EcKeysetGeneratorCommand($converter); + $command = new Console\EcKeysetGeneratorCommand(); $command->run($input, $output); } @@ -59,13 +56,12 @@ public function theEllipticCurveKeySetCreationCommandNeedTheCurveAndQuantityArgu */ public function iCannotCreateAnEllipticCurveKeySetWithAnUnsupportedCurve() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, 'curve' => 'P-128', ]); $output = new BufferedOutput(); - $command = new Console\EcKeysetGeneratorCommand($converter); + $command = new Console\EcKeysetGeneratorCommand(); $command->run($input, $output); } @@ -75,14 +71,13 @@ public function iCannotCreateAnEllipticCurveKeySetWithAnUnsupportedCurve() */ public function iCanCreateAnEllipticCurveKeySetWithCurveP256() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, 'curve' => 'P-256', '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\EcKeysetGeneratorCommand($converter); + $command = new Console\EcKeysetGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -97,12 +92,11 @@ public function iCanCreateAnEllipticCurveKeySetWithCurveP256() */ public function iCannotCreateAnOctetKeySetWithoutKeySetSize() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, ]); $output = new BufferedOutput(); - $command = new Console\OctKeysetGeneratorCommand($converter); + $command = new Console\OctKeysetGeneratorCommand(); $command->run($input, $output); } @@ -112,14 +106,13 @@ public function iCannotCreateAnOctetKeySetWithoutKeySetSize() */ public function iCanCreateAnOctetKeySet() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, 'size' => 256, '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\OctKeysetGeneratorCommand($converter); + $command = new Console\OctKeysetGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -134,12 +127,11 @@ public function iCanCreateAnOctetKeySet() */ public function iCannotCreateAnOctetKeySetPairWithoutKeySetCurve() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, ]); $output = new BufferedOutput(); - $command = new Console\OkpKeysetGeneratorCommand($converter); + $command = new Console\OkpKeysetGeneratorCommand(); $command->run($input, $output); } @@ -149,14 +141,13 @@ public function iCannotCreateAnOctetKeySetPairWithoutKeySetCurve() */ public function iCanCreateAnOctetKeySetPair() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, 'curve' => 'X25519', '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\OkpKeysetGeneratorCommand($converter); + $command = new Console\OkpKeysetGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); @@ -171,12 +162,11 @@ public function iCanCreateAnOctetKeySetPair() */ public function iCannotCreateAnRsaKeySetWithoutKeySetSize() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, ]); $output = new BufferedOutput(); - $command = new Console\RsaKeysetGeneratorCommand($converter); + $command = new Console\RsaKeysetGeneratorCommand(); $command->run($input, $output); } @@ -186,14 +176,13 @@ public function iCannotCreateAnRsaKeySetWithoutKeySetSize() */ public function iCanCreateAnRsaKeySet() { - $converter = new StandardConverter(); $input = new ArrayInput([ 'quantity' => 2, 'size' => 1024, '--random_id' => true, ]); $output = new BufferedOutput(); - $command = new Console\RsaKeysetGeneratorCommand($converter); + $command = new Console\RsaKeysetGeneratorCommand(); $command->run($input, $output); $content = $output->fetch(); diff --git a/src/Component/Console/X5ULoaderCommand.php b/src/Component/Console/X5ULoaderCommand.php index 167750ba..c76b6d41 100644 --- a/src/Component/Console/X5ULoaderCommand.php +++ b/src/Component/Console/X5ULoaderCommand.php @@ -13,7 +13,6 @@ namespace Jose\Component\Console; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\KeyManagement\X5UFactory; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -23,10 +22,10 @@ final class X5ULoaderCommand extends ObjectOutputCommand { private $x5uFactory; - public function __construct(X5UFactory $x5uFactory, JsonConverter $jsonConverter, ?string $name = null) + public function __construct(X5UFactory $x5uFactory, ?string $name = null) { $this->x5uFactory = $x5uFactory; - parent::__construct($jsonConverter, $name); + parent::__construct($name); } protected function configure() diff --git a/src/Component/Core/Converter/JsonConverter.php b/src/Component/Core/Converter/JsonConverter.php deleted file mode 100644 index daf55b7e..00000000 --- a/src/Component/Core/Converter/JsonConverter.php +++ /dev/null @@ -1,27 +0,0 @@ -options = $options; - $this->depth = $depth; - } - - public function encode($payload): string - { - return \json_encode($payload, $this->options, $this->depth); - } - - public function decode(string $payload, bool $associativeArray = true) - { - return \json_decode($payload, $associativeArray, $this->depth, $this->options); - } -} diff --git a/src/Component/Core/Tests/AlgorithmManagerFactoryTest.php b/src/Component/Core/Tests/AlgorithmManagerFactoryTest.php index 1a9537b0..0b7d5765 100644 --- a/src/Component/Core/Tests/AlgorithmManagerFactoryTest.php +++ b/src/Component/Core/Tests/AlgorithmManagerFactoryTest.php @@ -67,7 +67,7 @@ public function iCannotGetAnAlgorithmThatDoesNotExist() } /** - * @var null|AlgorithmManagerFactory + * @var AlgorithmManagerFactory|null */ private $algorithmManagerFactory; diff --git a/src/Component/Core/Tests/JsonConverterTest.php b/src/Component/Core/Tests/JsonConverterTest.php index 77320c35..fbca45f1 100644 --- a/src/Component/Core/Tests/JsonConverterTest.php +++ b/src/Component/Core/Tests/JsonConverterTest.php @@ -13,7 +13,7 @@ namespace Jose\Component\Core\Tests; -use Jose\Component\Core\Converter\StandardConverter; +use Jose\Component\Core\Util\JsonConverter; use PHPUnit\Framework\TestCase; /** @@ -27,8 +27,7 @@ class JsonConverterTest extends TestCase */ public function iCanConvertAnObjectIntoAJsonString() { - $converter = new StandardConverter(); - static::assertEquals('{"foo":"BAR"}', $converter->encode(['foo' => 'BAR'])); - static::assertEquals(['foo' => 'BAR'], $converter->decode('{"foo":"BAR"}')); + static::assertEquals('{"foo":"BAR"}', JsonConverter::encode(['foo' => 'BAR'])); + static::assertEquals(['foo' => 'BAR'], JsonConverter::decode('{"foo":"BAR"}')); } } diff --git a/src/Component/Core/Util/JsonConverter.php b/src/Component/Core/Util/JsonConverter.php new file mode 100644 index 00000000..0ecc6bd4 --- /dev/null +++ b/src/Component/Core/Util/JsonConverter.php @@ -0,0 +1,27 @@ +jsonConverter = $jsonConverter; $this->keyEncryptionAlgorithmManager = $keyEncryptionAlgorithmManager; $this->contentEncryptionAlgorithmManager = $contentEncryptionAlgorithmManager; $this->compressionManager = $compressionManager; @@ -151,7 +145,7 @@ public function getCompressionMethodManager(): CompressionMethodManager */ public function withPayload($payload): self { - $payload = \is_string($payload) ? $payload : $this->jsonConverter->encode($payload); + $payload = \is_string($payload) ? $payload : JsonConverter::encode($payload); if (false === \mb_detect_encoding($payload, 'UTF-8', true)) { throw new \InvalidArgumentException('The payload must be encoded in UTF-8'); } @@ -276,7 +270,7 @@ public function build(): JWE } else { $sharedProtectedHeader = $this->sharedProtectedHeader; } - $encodedSharedProtectedHeader = empty($sharedProtectedHeader) ? '' : Base64Url::encode($this->jsonConverter->encode($sharedProtectedHeader)); + $encodedSharedProtectedHeader = empty($sharedProtectedHeader) ? '' : Base64Url::encode(JsonConverter::encode($sharedProtectedHeader)); list($ciphertext, $iv, $tag) = $this->encryptJWE($cek, $encodedSharedProtectedHeader); diff --git a/src/Component/Encryption/JWEBuilderFactory.php b/src/Component/Encryption/JWEBuilderFactory.php index 62ffa718..60bab8f3 100644 --- a/src/Component/Encryption/JWEBuilderFactory.php +++ b/src/Component/Encryption/JWEBuilderFactory.php @@ -14,16 +14,10 @@ namespace Jose\Component\Encryption; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Encryption\Compression\CompressionMethodManagerFactory; class JWEBuilderFactory { - /** - * @var JsonConverter - */ - private $jsonEncoder; - /** * @var AlgorithmManagerFactory */ @@ -37,9 +31,8 @@ class JWEBuilderFactory /** * JWEBuilderFactory constructor. */ - public function __construct(JsonConverter $jsonEncoder, AlgorithmManagerFactory $algorithmManagerFactory, CompressionMethodManagerFactory $compressionMethodManagerFactory) + public function __construct(AlgorithmManagerFactory $algorithmManagerFactory, CompressionMethodManagerFactory $compressionMethodManagerFactory) { - $this->jsonEncoder = $jsonEncoder; $this->algorithmManagerFactory = $algorithmManagerFactory; $this->compressionMethodManagerFactory = $compressionMethodManagerFactory; } @@ -57,6 +50,6 @@ public function create(array $keyEncryptionAlgorithms, array $contentEncryptionA $contentEncryptionAlgorithmManager = $this->algorithmManagerFactory->create($contentEncryptionAlgorithm); $compressionMethodManager = $this->compressionMethodManagerFactory->create($compressionMethods); - return new JWEBuilder($this->jsonEncoder, $keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionMethodManager); + return new JWEBuilder($keyEncryptionAlgorithmManager, $contentEncryptionAlgorithmManager, $compressionMethodManager); } } diff --git a/src/Component/Encryption/Serializer/CompactSerializer.php b/src/Component/Encryption/Serializer/CompactSerializer.php index 9bf04efa..4c72f0f7 100644 --- a/src/Component/Encryption/Serializer/CompactSerializer.php +++ b/src/Component/Encryption/Serializer/CompactSerializer.php @@ -14,7 +14,7 @@ namespace Jose\Component\Encryption\Serializer; use Base64Url\Base64Url; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Encryption\JWE; use Jose\Component\Encryption\Recipient; @@ -22,19 +22,6 @@ final class CompactSerializer implements JWESerializer { public const NAME = 'jwe_compact'; - /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * JSONFlattenedSerializer constructor. - */ - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function displayName(): string { return 'JWE Compact'; @@ -75,7 +62,7 @@ public function unserialize(string $input): JWE try { $encodedSharedProtectedHeader = $parts[0]; - $sharedProtectedHeader = $this->jsonConverter->decode(Base64Url::decode($encodedSharedProtectedHeader)); + $sharedProtectedHeader = JsonConverter::decode(Base64Url::decode($encodedSharedProtectedHeader)); $encryptedKey = empty($parts[1]) ? null : Base64Url::decode($parts[1]); $iv = Base64Url::decode($parts[2]); $ciphertext = Base64Url::decode($parts[3]); diff --git a/src/Component/Encryption/Serializer/JSONFlattenedSerializer.php b/src/Component/Encryption/Serializer/JSONFlattenedSerializer.php index 593d65b2..67b160ee 100644 --- a/src/Component/Encryption/Serializer/JSONFlattenedSerializer.php +++ b/src/Component/Encryption/Serializer/JSONFlattenedSerializer.php @@ -14,7 +14,7 @@ namespace Jose\Component\Encryption\Serializer; use Base64Url\Base64Url; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Encryption\JWE; use Jose\Component\Encryption\Recipient; @@ -22,19 +22,6 @@ final class JSONFlattenedSerializer implements JWESerializer { public const NAME = 'jwe_json_flattened'; - /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * JSONFlattenedSerializer constructor. - */ - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function displayName(): string { return 'JWE JSON Flattened'; @@ -72,12 +59,12 @@ public function serialize(JWE $jwe, ?int $recipientIndex = null): string $data['encrypted_key'] = Base64Url::encode($recipient->getEncryptedKey()); } - return $this->jsonConverter->encode($data); + return JsonConverter::encode($data); } public function unserialize(string $input): JWE { - $data = $this->jsonConverter->decode($input); + $data = JsonConverter::decode($input); $this->checkData($data); $ciphertext = Base64Url::decode($data['ciphertext']); @@ -109,7 +96,7 @@ private function checkData($data) private function processHeaders(array $data): array { $encodedSharedProtectedHeader = \array_key_exists('protected', $data) ? $data['protected'] : null; - $sharedProtectedHeader = $encodedSharedProtectedHeader ? $this->jsonConverter->decode(Base64Url::decode($encodedSharedProtectedHeader)) : []; + $sharedProtectedHeader = $encodedSharedProtectedHeader ? JsonConverter::decode(Base64Url::decode($encodedSharedProtectedHeader)) : []; $sharedHeader = \array_key_exists('unprotected', $data) ? $data['unprotected'] : []; return [$encodedSharedProtectedHeader, $sharedProtectedHeader, $sharedHeader]; diff --git a/src/Component/Encryption/Serializer/JSONGeneralSerializer.php b/src/Component/Encryption/Serializer/JSONGeneralSerializer.php index b67304f4..6f920f0a 100644 --- a/src/Component/Encryption/Serializer/JSONGeneralSerializer.php +++ b/src/Component/Encryption/Serializer/JSONGeneralSerializer.php @@ -14,7 +14,7 @@ namespace Jose\Component\Encryption\Serializer; use Base64Url\Base64Url; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Encryption\JWE; use Jose\Component\Encryption\Recipient; @@ -22,19 +22,6 @@ final class JSONGeneralSerializer implements JWESerializer { public const NAME = 'jwe_json_general'; - /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * JSONFlattenedSerializer constructor. - */ - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function displayName(): string { return 'JWE JSON General'; @@ -77,12 +64,12 @@ public function serialize(JWE $jwe, ?int $recipientIndex = null): string $data['recipients'][] = $temp; } - return $this->jsonConverter->encode($data); + return JsonConverter::encode($data); } public function unserialize(string $input): JWE { - $data = $this->jsonConverter->decode($input); + $data = JsonConverter::decode($input); $this->checkData($data); $ciphertext = Base64Url::decode($data['ciphertext']); @@ -125,7 +112,7 @@ private function processRecipient(array $recipient): array private function processHeaders(array $data): array { $encodedSharedProtectedHeader = \array_key_exists('protected', $data) ? $data['protected'] : null; - $sharedProtectedHeader = $encodedSharedProtectedHeader ? $this->jsonConverter->decode(Base64Url::decode($encodedSharedProtectedHeader)) : []; + $sharedProtectedHeader = $encodedSharedProtectedHeader ? JsonConverter::decode(Base64Url::decode($encodedSharedProtectedHeader)) : []; $sharedHeader = \array_key_exists('unprotected', $data) ? $data['unprotected'] : []; return [$encodedSharedProtectedHeader, $sharedProtectedHeader, $sharedHeader]; diff --git a/src/Component/Encryption/Tests/EncryptionTest.php b/src/Component/Encryption/Tests/EncryptionTest.php index fe4edb1d..10731fd3 100644 --- a/src/Component/Encryption/Tests/EncryptionTest.php +++ b/src/Component/Encryption/Tests/EncryptionTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Encryption\Tests; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Encryption\Algorithm\ContentEncryption; use Jose\Component\Encryption\Algorithm\KeyEncryption; use Jose\Component\Encryption\Compression; @@ -90,7 +89,6 @@ protected function getJWEBuilderFactory(): JWEBuilderFactory { if (null === $this->jweBuilderFactory) { $this->jweBuilderFactory = new JWEBuilderFactory( - new StandardConverter(), $this->getAlgorithmManagerFactory(), $this->getCompressionMethodManagerFactory() ); @@ -135,7 +133,7 @@ protected function getJWELoaderFactory(): JWELoaderFactory } /** - * @var null|Serializer\JWESerializerManagerFactory + * @var Serializer\JWESerializerManagerFactory|null */ private $jwsSerializerManagerFactory = null; @@ -143,16 +141,16 @@ protected function getJWESerializerManagerFactory(): Serializer\JWESerializerMan { if (null === $this->jwsSerializerManagerFactory) { $this->jwsSerializerManagerFactory = new Serializer\JWESerializerManagerFactory(); - $this->jwsSerializerManagerFactory->add(new Serializer\CompactSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new Serializer\JSONFlattenedSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new Serializer\JSONGeneralSerializer(new StandardConverter())); + $this->jwsSerializerManagerFactory->add(new Serializer\CompactSerializer()); + $this->jwsSerializerManagerFactory->add(new Serializer\JSONFlattenedSerializer()); + $this->jwsSerializerManagerFactory->add(new Serializer\JSONGeneralSerializer()); } return $this->jwsSerializerManagerFactory; } /** - * @var null|Serializer\JWESerializerManager + * @var Serializer\JWESerializerManager|null */ private $jwsSerializerManager = null; @@ -160,9 +158,9 @@ protected function getJWESerializerManager(): Serializer\JWESerializerManager { if (null === $this->jwsSerializerManager) { $this->jwsSerializerManager = new Serializer\JWESerializerManager([ - new Serializer\CompactSerializer(new StandardConverter()), - new Serializer\JSONFlattenedSerializer(new StandardConverter()), - new Serializer\JSONGeneralSerializer(new StandardConverter()), + new Serializer\CompactSerializer(), + new Serializer\JSONFlattenedSerializer(), + new Serializer\JSONGeneralSerializer(), ]); } diff --git a/src/Component/Encryption/Tests/JWESplitTest.php b/src/Component/Encryption/Tests/JWESplitTest.php index b78e7ef1..7860125a 100644 --- a/src/Component/Encryption/Tests/JWESplitTest.php +++ b/src/Component/Encryption/Tests/JWESplitTest.php @@ -13,7 +13,6 @@ namespace Jose\Component\Encryption\Tests; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Encryption\Serializer\JSONGeneralSerializer; /** @@ -27,7 +26,7 @@ class JWESplitTest extends EncryptionTest public function aJweObjectWithMoreThanOneRecipientCanBeSplittedIntoSeveralJweObjects() { $input = '{"recipients":[{"encrypted_key":"dYOD28kab0Vvf4ODgxVAJXgHcSZICSOp8M51zjwj4w6Y5G4XJQsNNIBiqyvUUAOcpL7S7-cFe7Pio7gV_Q06WmCSa-vhW6me4bWrBf7cHwEQJdXihidAYWVajJIaKMXMvFRMV6iDlRr076DFthg2_AV0_tSiV6xSEIFqt1xnYPpmP91tc5WJDOGb-wqjw0-b-S1laS11QVbuP78dQ7Fa0zAVzzjHX-xvyM2wxj_otxr9clN1LnZMbeYSrRicJK5xodvWgkpIdkMHo4LvdhRRvzoKzlic89jFWPlnBq_V4n5trGuExtp_-dbHcGlihqc_wGgho9fLMK8JOArYLcMDNQ","header":{"alg":"RSA1_5","kid":"frodo.baggins@hobbiton.example"}},{"encrypted_key":"ExInT0io9BqBMYF6-maw5tZlgoZXThD1zWKsHixJuw_elY4gSSId_w","header":{"alg":"ECDH-ES+A256KW","kid":"peregrin.took@tuckborough.example","epk":{"kty":"EC","crv":"P-384","x":"Uzdvk3pi5wKCRc1izp5_r0OjeqT-I68i8g2b8mva8diRhsE2xAn2DtMRb25Ma2CX","y":"VDrRyFJh-Kwd1EjAgmj5Eo-CTHAZ53MC7PjjpLioy3ylEjI1pOMbw91fzZ84pbfm"}}},{"encrypted_key":"a7CclAejo_7JSuPB8zeagxXRam8dwCfmkt9-WyTpS1E","header":{"alg":"A256GCMKW","kid":"18ec08e1-bfa9-4d95-b205-2b4dd1d4321d","tag":"59Nqh1LlYtVIhfD3pgRGvw","iv":"AvpeoPZ9Ncn9mkBn"}}],"unprotected":{"cty":"text/plain"},"protected":"eyJlbmMiOiJBMTI4Q0JDLUhTMjU2In0","iv":"VgEIHY20EnzUtZFl2RpB1g","ciphertext":"ajm2Q-OpPXCr7-MHXicknb1lsxLdXxK_yLds0KuhJzfWK04SjdxQeSw2L9mu3a_k1C55kCQ_3xlkcVKC5yr__Is48VOoK0k63_QRM9tBURMFqLByJ8vOYQX0oJW4VUHJLmGhF-tVQWB7Kz8mr8zeE7txF0MSaP6ga7-siYxStR7_G07Thd1jh-zGT0wxM5g-VRORtq0K6AXpLlwEqRp7pkt2zRM0ZAXqSpe1O6FJ7FHLDyEFnD-zDIZukLpCbzhzMDLLw2-8I14FQrgi-iEuzHgIJFIJn2wh9Tj0cg_kOZy9BqMRZbmYXMY9YQjorZ_P_JYG3ARAIF3OjDNqpdYe-K_5Q5crGJSDNyij_ygEiItR5jssQVH2ofDQdLChtazE","tag":"BESYyFN7T09KY7i8zKs5_g"}'; - $serializer = new JSONGeneralSerializer(new StandardConverter()); + $serializer = new JSONGeneralSerializer(); $jwe = $serializer->unserialize($input); $split = $jwe->split(); diff --git a/src/Component/KeyManagement/JKUFactory.php b/src/Component/KeyManagement/JKUFactory.php index 9733acb5..cfed4a6e 100644 --- a/src/Component/KeyManagement/JKUFactory.php +++ b/src/Component/KeyManagement/JKUFactory.php @@ -13,24 +13,11 @@ namespace Jose\Component\KeyManagement; -use Http\Client\HttpClient; -use Http\Message\RequestFactory; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; class JKUFactory extends UrlKeySetFactory { - private $jsonConverter; - - /** - * JKUFactory constructor. - */ - public function __construct(JsonConverter $jsonConverter, HttpClient $client, RequestFactory $requestFactory) - { - parent::__construct($client, $requestFactory); - $this->jsonConverter = $jsonConverter; - } - /** * This method will try to fetch the url a retrieve the key set. * Throws an exception in case of failure. @@ -38,7 +25,7 @@ public function __construct(JsonConverter $jsonConverter, HttpClient $client, Re public function loadFromUrl(string $url, array $header = []): JWKSet { $content = $this->getContent($url, $header); - $data = $this->jsonConverter->decode($content); + $data = JsonConverter::decode($content); if (!\is_array($data)) { throw new \RuntimeException('Invalid content.'); } diff --git a/src/Component/KeyManagement/Tests/JWKAnalyzerTest.php b/src/Component/KeyManagement/Tests/JWKAnalyzerTest.php index 3f117ce3..07ea3fa0 100644 --- a/src/Component/KeyManagement/Tests/JWKAnalyzerTest.php +++ b/src/Component/KeyManagement/Tests/JWKAnalyzerTest.php @@ -60,13 +60,13 @@ public function theRsaKeyHasALowExponent() $messages = $this->getKeyAnalyzer()->analyze($key); foreach ($messages->all() as $message) { - if ($message->getMessage() === 'The exponent is too low. It should be at least 65537.') { + if ('The exponent is too low. It should be at least 65537.' === $message->getMessage()) { static::assertTrue(true); return; } } - $this->fail('The low exponent should be catched'); + static::fail('The low exponent should be catched'); } /** diff --git a/src/Component/KeyManagement/Tests/UrlKeySetFactoryTest.php b/src/Component/KeyManagement/Tests/UrlKeySetFactoryTest.php index f38478f0..e472680e 100644 --- a/src/Component/KeyManagement/Tests/UrlKeySetFactoryTest.php +++ b/src/Component/KeyManagement/Tests/UrlKeySetFactoryTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\KeyManagement\Tests; use Http\Mock\Client; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWKSet; use Jose\Component\KeyManagement\JKUFactory; use Jose\Component\KeyManagement\X5UFactory; @@ -114,7 +113,6 @@ private function getJKUFactory(): JKUFactory { if (null === $this->jkuFactory) { $this->jkuFactory = new JKUFactory( - new StandardConverter(), $this->getHttpClient(), new HttpMessageFactory() ); @@ -132,7 +130,6 @@ private function getX5UFactory(): X5UFactory { if (null === $this->x5uFactory) { $this->x5uFactory = new X5UFactory( - new StandardConverter(), $this->getHttpClient(), new HttpMessageFactory() ); diff --git a/src/Component/KeyManagement/X5UFactory.php b/src/Component/KeyManagement/X5UFactory.php index 165edb18..a192be4b 100644 --- a/src/Component/KeyManagement/X5UFactory.php +++ b/src/Component/KeyManagement/X5UFactory.php @@ -13,26 +13,13 @@ namespace Jose\Component\KeyManagement; -use Http\Client\HttpClient; -use Http\Message\RequestFactory; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\KeyManagement\KeyConverter\KeyConverter; class X5UFactory extends UrlKeySetFactory { - private $jsonConverter; - - /** - * X5UFactory constructor. - */ - public function __construct(JsonConverter $jsonConverter, HttpClient $client, RequestFactory $requestFactory) - { - $this->jsonConverter = $jsonConverter; - parent::__construct($client, $requestFactory); - } - /** * This method will try to fetch the url a retrieve the key set. * Throws an exception in case of failure. @@ -40,7 +27,7 @@ public function __construct(JsonConverter $jsonConverter, HttpClient $client, Re public function loadFromUrl(string $url, array $header = []): JWKSet { $content = $this->getContent($url, $header); - $data = $this->jsonConverter->decode($content); + $data = JsonConverter::decode($content); if (!\is_array($data)) { throw new \RuntimeException('Invalid content.'); } diff --git a/src/Component/NestedToken/Tests/NestedTokenTest.php b/src/Component/NestedToken/Tests/NestedTokenTest.php index 742e4bf5..65b7efd8 100644 --- a/src/Component/NestedToken/Tests/NestedTokenTest.php +++ b/src/Component/NestedToken/Tests/NestedTokenTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\NestedToken\Tests; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Encryption\Algorithm\ContentEncryption; use Jose\Component\Encryption\Algorithm\KeyEncryption; use Jose\Component\Encryption\Compression; @@ -90,7 +89,6 @@ protected function getJWEBuilderFactory(): JWEBuilderFactory { if (null === $this->jweBuilderFactory) { $this->jweBuilderFactory = new JWEBuilderFactory( - new StandardConverter(), $this->getAlgorithmManagerFactory(), $this->getCompressionMethodManagerFactory() ); @@ -135,7 +133,7 @@ protected function getJWELoaderFactory(): JWELoaderFactory } /** - * @var null|Serializer\JWESerializerManagerFactory + * @var Serializer\JWESerializerManagerFactory|null */ private $jwsSerializerManagerFactory = null; @@ -143,16 +141,16 @@ protected function getJWESerializerManagerFactory(): Serializer\JWESerializerMan { if (null === $this->jwsSerializerManagerFactory) { $this->jwsSerializerManagerFactory = new Serializer\JWESerializerManagerFactory(); - $this->jwsSerializerManagerFactory->add(new Serializer\CompactSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new Serializer\JSONFlattenedSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new Serializer\JSONGeneralSerializer(new StandardConverter())); + $this->jwsSerializerManagerFactory->add(new Serializer\CompactSerializer()); + $this->jwsSerializerManagerFactory->add(new Serializer\JSONFlattenedSerializer()); + $this->jwsSerializerManagerFactory->add(new Serializer\JSONGeneralSerializer()); } return $this->jwsSerializerManagerFactory; } /** - * @var null|Serializer\JWESerializerManager + * @var Serializer\JWESerializerManager|null */ private $jwsSerializerManager = null; @@ -160,9 +158,9 @@ protected function getJWESerializerManager(): Serializer\JWESerializerManager { if (null === $this->jwsSerializerManager) { $this->jwsSerializerManager = new Serializer\JWESerializerManager([ - new Serializer\CompactSerializer(new StandardConverter()), - new Serializer\JSONFlattenedSerializer(new StandardConverter()), - new Serializer\JSONGeneralSerializer(new StandardConverter()), + new Serializer\CompactSerializer(), + new Serializer\JSONFlattenedSerializer(), + new Serializer\JSONGeneralSerializer(), ]); } diff --git a/src/Component/NestedToken/Tests/NestingTokenBuilderTest.php b/src/Component/NestedToken/Tests/NestingTokenBuilderTest.php index ed911f75..aa8cb137 100644 --- a/src/Component/NestedToken/Tests/NestingTokenBuilderTest.php +++ b/src/Component/NestedToken/Tests/NestingTokenBuilderTest.php @@ -15,7 +15,6 @@ use Jose\Component\Checker\HeaderCheckerManagerFactory; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Encryption\Algorithm\ContentEncryption\A128GCM; use Jose\Component\Encryption\Algorithm\KeyEncryption\RSAOAEP; @@ -119,7 +118,6 @@ protected function getJWSBuilderFactory(): JWSBuilderFactory { if (null === $this->jwsBuilderFactory) { $this->jwsBuilderFactory = new JWSBuilderFactory( - new StandardConverter(), $this->getAlgorithmManagerFactory() ); } @@ -136,7 +134,6 @@ protected function getJWEBuilderFactory(): JWEBuilderFactory { if (null === $this->jweBuilderFactory) { $this->jweBuilderFactory = new JWEBuilderFactory( - new StandardConverter(), $this->getAlgorithmManagerFactory(), $this->getCompressionMethodManagerFactory() ); @@ -167,9 +164,9 @@ private function getNestedTokenBuilderFactory(): NestedTokenBuilderFactory private function getJWSSerializerManagerFactory(): JwsSerializer\JWSSerializerManagerFactory { $jwsSerializerManagerFactory = new JwsSerializer\JWSSerializerManagerFactory(); - $jwsSerializerManagerFactory->add(new JwsSerializer\CompactSerializer(new StandardConverter())); - $jwsSerializerManagerFactory->add(new JwsSerializer\JSONFlattenedSerializer(new StandardConverter())); - $jwsSerializerManagerFactory->add(new JwsSerializer\JSONGeneralSerializer(new StandardConverter())); + $jwsSerializerManagerFactory->add(new JwsSerializer\CompactSerializer()); + $jwsSerializerManagerFactory->add(new JwsSerializer\JSONFlattenedSerializer()); + $jwsSerializerManagerFactory->add(new JwsSerializer\JSONGeneralSerializer()); return $jwsSerializerManagerFactory; } @@ -209,7 +206,7 @@ private function getCompressionMethodManagerFactory(): CompressionMethodManagerF } /** - * @var null|JweSerializer\JWESerializerManagerFactory + * @var JweSerializer\JWESerializerManagerFactory|null */ private $jwsSerializerManagerFactory = null; @@ -217,9 +214,9 @@ private function getJWESerializerManagerFactory(): JweSerializer\JWESerializerMa { if (null === $this->jwsSerializerManagerFactory) { $this->jwsSerializerManagerFactory = new JweSerializer\JWESerializerManagerFactory(); - $this->jwsSerializerManagerFactory->add(new JweSerializer\CompactSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONFlattenedSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONGeneralSerializer(new StandardConverter())); + $this->jwsSerializerManagerFactory->add(new JweSerializer\CompactSerializer()); + $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONFlattenedSerializer()); + $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONGeneralSerializer()); } return $this->jwsSerializerManagerFactory; diff --git a/src/Component/NestedToken/Tests/NestingTokenUsingNestedTokenLoaderTest.php b/src/Component/NestedToken/Tests/NestingTokenUsingNestedTokenLoaderTest.php index 2916661b..a18e2782 100644 --- a/src/Component/NestedToken/Tests/NestingTokenUsingNestedTokenLoaderTest.php +++ b/src/Component/NestedToken/Tests/NestingTokenUsingNestedTokenLoaderTest.php @@ -15,7 +15,6 @@ use Jose\Component\Checker\HeaderCheckerManagerFactory; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; use Jose\Component\Encryption\Algorithm\ContentEncryption\A128GCM; @@ -186,9 +185,9 @@ private function getHeaderCheckerManagerFactory(): HeaderCheckerManagerFactory private function getJWSSerializerManagerFactory(): JwsSerializer\JWSSerializerManagerFactory { $jwsSerializerManagerFactory = new JwsSerializer\JWSSerializerManagerFactory(); - $jwsSerializerManagerFactory->add(new JwsSerializer\CompactSerializer(new StandardConverter())); - $jwsSerializerManagerFactory->add(new JwsSerializer\JSONFlattenedSerializer(new StandardConverter())); - $jwsSerializerManagerFactory->add(new JwsSerializer\JSONGeneralSerializer(new StandardConverter())); + $jwsSerializerManagerFactory->add(new JwsSerializer\CompactSerializer()); + $jwsSerializerManagerFactory->add(new JwsSerializer\JSONFlattenedSerializer()); + $jwsSerializerManagerFactory->add(new JwsSerializer\JSONGeneralSerializer()); return $jwsSerializerManagerFactory; } @@ -254,7 +253,7 @@ private function getJWEDecrypterFactory(): JWEDecrypterFactory } /** - * @var null|JweSerializer\JWESerializerManagerFactory + * @var JweSerializer\JWESerializerManagerFactory|null */ private $jwsSerializerManagerFactory = null; @@ -262,9 +261,9 @@ private function getJWESerializerManagerFactory(): JweSerializer\JWESerializerMa { if (null === $this->jwsSerializerManagerFactory) { $this->jwsSerializerManagerFactory = new JweSerializer\JWESerializerManagerFactory(); - $this->jwsSerializerManagerFactory->add(new JweSerializer\CompactSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONFlattenedSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONGeneralSerializer(new StandardConverter())); + $this->jwsSerializerManagerFactory->add(new JweSerializer\CompactSerializer()); + $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONFlattenedSerializer()); + $this->jwsSerializerManagerFactory->add(new JweSerializer\JSONGeneralSerializer()); } return $this->jwsSerializerManagerFactory; diff --git a/src/Component/Signature/JWSBuilder.php b/src/Component/Signature/JWSBuilder.php index 273cd4aa..d61f5ae7 100644 --- a/src/Component/Signature/JWSBuilder.php +++ b/src/Component/Signature/JWSBuilder.php @@ -15,20 +15,15 @@ use Base64Url\Base64Url; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\JsonConverter; use Jose\Component\Core\JWK; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Core\Util\KeyChecker; use Jose\Component\Signature\Algorithm\SignatureAlgorithm; class JWSBuilder { /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * @var null|string + * @var string|null */ private $payload; @@ -48,16 +43,15 @@ class JWSBuilder private $signatureAlgorithmManager; /** - * @var null|bool + * @var bool|null */ private $isPayloadEncoded = null; /** * JWSBuilder constructor. */ - public function __construct(JsonConverter $jsonConverter, AlgorithmManager $signatureAlgorithmManager) + public function __construct(AlgorithmManager $signatureAlgorithmManager) { - $this->jsonConverter = $jsonConverter; $this->signatureAlgorithmManager = $signatureAlgorithmManager; } @@ -155,7 +149,7 @@ public function build(): JWS $protectedHeader = $signature['protected_header']; /** @var array $header */ $header = $signature['header']; - $encodedProtectedHeader = empty($protectedHeader) ? null : Base64Url::encode($this->jsonConverter->encode($protectedHeader)); + $encodedProtectedHeader = empty($protectedHeader) ? null : Base64Url::encode(JsonConverter::encode($protectedHeader)); $input = \sprintf('%s.%s', $encodedProtectedHeader, $encodedPayload); $s = $signatureAlgorithm->sign($signatureKey, $input); $jws = $jws->addSignature($s, $protectedHeader, $encodedProtectedHeader, $header); diff --git a/src/Component/Signature/JWSBuilderFactory.php b/src/Component/Signature/JWSBuilderFactory.php index 16ccd56f..e1c77b4e 100644 --- a/src/Component/Signature/JWSBuilderFactory.php +++ b/src/Component/Signature/JWSBuilderFactory.php @@ -14,17 +14,13 @@ namespace Jose\Component\Signature; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\JsonConverter; class JWSBuilderFactory { - private $jsonEncoder; - private $signatureAlgorithmManagerFactory; - public function __construct(JsonConverter $jsonEncoder, AlgorithmManagerFactory $signatureAlgorithmManagerFactory) + public function __construct(AlgorithmManagerFactory $signatureAlgorithmManagerFactory) { - $this->jsonEncoder = $jsonEncoder; $this->signatureAlgorithmManagerFactory = $signatureAlgorithmManagerFactory; } @@ -37,6 +33,6 @@ public function create(array $algorithms): JWSBuilder { $algorithmManager = $this->signatureAlgorithmManagerFactory->create($algorithms); - return new JWSBuilder($this->jsonEncoder, $algorithmManager); + return new JWSBuilder($algorithmManager); } } diff --git a/src/Component/Signature/JWSVerifier.php b/src/Component/Signature/JWSVerifier.php index d552bb52..a14c3f82 100644 --- a/src/Component/Signature/JWSVerifier.php +++ b/src/Component/Signature/JWSVerifier.php @@ -63,7 +63,7 @@ public function verifyWithKey(JWS $jws, JWK $jwk, int $signature, ?string $detac * @param JWS $jws A JWS object * @param JWKSet $jwkset The signature will be verified using keys in the key set * @param JWK $jwk The key used to verify the signature in case of success - * @param null|string $detachedPayload If not null, the value must be the detached payload encoded in Base64 URL safe. If the input contains a payload, throws an exception. + * @param string|null $detachedPayload If not null, the value must be the detached payload encoded in Base64 URL safe. If the input contains a payload, throws an exception. * * @return bool true if the verification of the signature succeeded, else false */ diff --git a/src/Component/Signature/Serializer/CompactSerializer.php b/src/Component/Signature/Serializer/CompactSerializer.php index 32d274a4..eb40fea4 100644 --- a/src/Component/Signature/Serializer/CompactSerializer.php +++ b/src/Component/Signature/Serializer/CompactSerializer.php @@ -14,26 +14,13 @@ namespace Jose\Component\Signature\Serializer; use Base64Url\Base64Url; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Signature\JWS; final class CompactSerializer extends Serializer { public const NAME = 'jws_compact'; - /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * JSONFlattenedSerializer constructor. - */ - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function displayName(): string { return 'JWS Compact'; @@ -76,7 +63,7 @@ public function unserialize(string $input): JWS try { $encodedProtectedHeader = $parts[0]; - $protectedHeader = $this->jsonConverter->decode(Base64Url::decode($parts[0])); + $protectedHeader = JsonConverter::decode(Base64Url::decode($parts[0])); if (empty($parts[1])) { $payload = null; $encodedPayload = null; diff --git a/src/Component/Signature/Serializer/JSONFlattenedSerializer.php b/src/Component/Signature/Serializer/JSONFlattenedSerializer.php index b2c95358..b8b27041 100644 --- a/src/Component/Signature/Serializer/JSONFlattenedSerializer.php +++ b/src/Component/Signature/Serializer/JSONFlattenedSerializer.php @@ -14,26 +14,13 @@ namespace Jose\Component\Signature\Serializer; use Base64Url\Base64Url; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Signature\JWS; final class JSONFlattenedSerializer extends Serializer { public const NAME = 'jws_json_flattened'; - /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * JSONFlattenedSerializer constructor. - */ - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function displayName(): string { return 'JWS JSON Flattened'; @@ -65,12 +52,12 @@ public function serialize(JWS $jws, ?int $signatureIndex = null): string } $data['signature'] = Base64Url::encode($signature->getSignature()); - return $this->jsonConverter->encode($data); + return JsonConverter::encode($data); } public function unserialize(string $input): JWS { - $data = $this->jsonConverter->decode($input); + $data = JsonConverter::decode($input); if (!\is_array($data) || !\array_key_exists('signature', $data)) { throw new \InvalidArgumentException('Unsupported input.'); } @@ -79,7 +66,7 @@ public function unserialize(string $input): JWS if (\array_key_exists('protected', $data)) { $encodedProtectedHeader = $data['protected']; - $protectedHeader = $this->jsonConverter->decode(Base64Url::decode($data['protected'])); + $protectedHeader = JsonConverter::decode(Base64Url::decode($data['protected'])); } else { $encodedProtectedHeader = null; $protectedHeader = []; diff --git a/src/Component/Signature/Serializer/JSONGeneralSerializer.php b/src/Component/Signature/Serializer/JSONGeneralSerializer.php index 8ba7249a..04d9ee0c 100644 --- a/src/Component/Signature/Serializer/JSONGeneralSerializer.php +++ b/src/Component/Signature/Serializer/JSONGeneralSerializer.php @@ -14,26 +14,13 @@ namespace Jose\Component\Signature\Serializer; use Base64Url\Base64Url; -use Jose\Component\Core\Converter\JsonConverter; +use Jose\Component\Core\Util\JsonConverter; use Jose\Component\Signature\JWS; final class JSONGeneralSerializer extends Serializer { public const NAME = 'jws_json_general'; - /** - * @var JsonConverter - */ - private $jsonConverter; - - /** - * JSONFlattenedSerializer constructor. - */ - public function __construct(JsonConverter $jsonConverter) - { - $this->jsonConverter = $jsonConverter; - } - public function displayName(): string { return 'JWS JSON General'; @@ -73,7 +60,7 @@ public function serialize(JWS $jws, ?int $signatureIndex = null): string $data['signatures'][] = $tmp; } - return $this->jsonConverter->encode($data); + return JsonConverter::encode($data); } private function checkData($data) @@ -92,7 +79,7 @@ private function checkSignature($signature) public function unserialize(string $input): JWS { - $data = $this->jsonConverter->decode($input); + $data = JsonConverter::decode($input); $this->checkData($data); $isPayloadEncoded = null; @@ -139,7 +126,7 @@ private function processIsPayloadEncoded(?bool $isPayloadEncoded, array $protect private function processHeaders(array $signature): array { $encodedProtectedHeader = \array_key_exists('protected', $signature) ? $signature['protected'] : null; - $protectedHeader = null !== $encodedProtectedHeader ? $this->jsonConverter->decode(Base64Url::decode($encodedProtectedHeader)) : []; + $protectedHeader = null !== $encodedProtectedHeader ? JsonConverter::decode(Base64Url::decode($encodedProtectedHeader)) : []; $header = \array_key_exists('header', $signature) ? $signature['header'] : []; return [$encodedProtectedHeader, $protectedHeader, $header]; diff --git a/src/Component/Signature/Tests/JWSSplitTest.php b/src/Component/Signature/Tests/JWSSplitTest.php index 02a46ece..c0d0c7aa 100644 --- a/src/Component/Signature/Tests/JWSSplitTest.php +++ b/src/Component/Signature/Tests/JWSSplitTest.php @@ -13,7 +13,6 @@ namespace Jose\Component\Signature\Tests; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Signature\JWS; use Jose\Component\Signature\Serializer\JSONGeneralSerializer; @@ -28,7 +27,7 @@ class JWSSplitTest extends SignatureTest public function aJwsObjectWithMoreThanOneRecipientCanBeSplittedIntoSeveralJwsObjects() { $input = '{"payload":"SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4gWW91IHN0ZXAgb250byB0aGUgcm9hZCwgYW5kIGlmIHlvdSBkb24ndCBrZWVwIHlvdXIgZmVldCwgdGhlcmXigJlzIG5vIGtub3dpbmcgd2hlcmUgeW91IG1pZ2h0IGJlIHN3ZXB0IG9mZiB0by4","signatures":[{"protected":"eyJhbGciOiJSUzI1NiJ9","header":{"kid":"bilbo.baggins@hobbiton.example"},"signature":"MIsjqtVlOpa71KE-Mss8_Nq2YH4FGhiocsqrgi5NvyG53uoimic1tcMdSg-qptrzZc7CG6Svw2Y13TDIqHzTUrL_lR2ZFcryNFiHkSw129EghGpwkpxaTn_THJTCglNbADko1MZBCdwzJxwqZc-1RlpO2HibUYyXSwO97BSe0_evZKdjvvKSgsIqjytKSeAMbhMBdMma622_BG5t4sdbuCHtFjp9iJmkio47AIwqkZV1aIZsv33uPUqBBCXbYoQJwt7mxPftHmNlGoOSMxR_3thmXTCm4US-xiNOyhbm8afKK64jU6_TPtQHiJeQJxz9G3Tx-083B745_AfYOnlC9w"},{"header":{"alg":"ES512","kid":"bilbo.baggins@hobbiton.example"},"signature":"ARcVLnaJJaUWG8fG-8t5BREVAuTY8n8YHjwDO1muhcdCoFZFFjfISu0Cdkn9Ybdlmi54ho0x924DUz8sK7ZXkhc7AFM8ObLfTvNCrqcI3Jkl2U5IX3utNhODH6v7xgy1Qahsn0fyb4zSAkje8bAWz4vIfj5pCMYxxm4fgV3q7ZYhm5eD"},{"protected":"eyJhbGciOiJIUzI1NiIsImtpZCI6IjAxOGMwYWU1LTRkOWItNDcxYi1iZmQ2LWVlZjMxNGJjNzAzNyJ9","signature":"s0h6KThzkfBBBkLspW1h84VsJZFTsPPqMDA7g1Md7p0"}]}'; - $serializer = new JSONGeneralSerializer(new StandardConverter()); + $serializer = new JSONGeneralSerializer(); $jws = $serializer->unserialize($input); $split = $jws->split(); diff --git a/src/Component/Signature/Tests/SignatureTest.php b/src/Component/Signature/Tests/SignatureTest.php index 7116c701..30f03668 100644 --- a/src/Component/Signature/Tests/SignatureTest.php +++ b/src/Component/Signature/Tests/SignatureTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Tests; use Jose\Component\Core\AlgorithmManagerFactory; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Signature\Algorithm; use Jose\Component\Signature\JWSBuilderFactory; use Jose\Component\Signature\JWSLoaderFactory; @@ -61,7 +60,6 @@ protected function getJWSBuilderFactory(): JWSBuilderFactory { if (null === $this->jwsBuilderFactory) { $this->jwsBuilderFactory = new JWSBuilderFactory( - new StandardConverter(), $this->getAlgorithmManagerFactory() ); } @@ -86,7 +84,7 @@ protected function getJWSVerifierFactory(): JWSVerifierFactory } /** - * @var null|Serializer\JWSSerializerManagerFactory + * @var Serializer\JWSSerializerManagerFactory|null */ private $jwsSerializerManagerFactory = null; @@ -94,16 +92,16 @@ protected function getJWSSerializerManagerFactory(): Serializer\JWSSerializerMan { if (null === $this->jwsSerializerManagerFactory) { $this->jwsSerializerManagerFactory = new Serializer\JWSSerializerManagerFactory(); - $this->jwsSerializerManagerFactory->add(new Serializer\CompactSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new Serializer\JSONFlattenedSerializer(new StandardConverter())); - $this->jwsSerializerManagerFactory->add(new Serializer\JSONGeneralSerializer(new StandardConverter())); + $this->jwsSerializerManagerFactory->add(new Serializer\CompactSerializer()); + $this->jwsSerializerManagerFactory->add(new Serializer\JSONFlattenedSerializer()); + $this->jwsSerializerManagerFactory->add(new Serializer\JSONGeneralSerializer()); } return $this->jwsSerializerManagerFactory; } /** - * @var null|Serializer\JWSSerializerManager + * @var Serializer\JWSSerializerManager|null */ private $jwsSerializerManager = null; @@ -111,9 +109,9 @@ protected function getJWSSerializerManager(): Serializer\JWSSerializerManager { if (null === $this->jwsSerializerManager) { $this->jwsSerializerManager = new Serializer\JWSSerializerManager([ - new Serializer\CompactSerializer(new StandardConverter()), - new Serializer\JSONFlattenedSerializer(new StandardConverter()), - new Serializer\JSONGeneralSerializer(new StandardConverter()), + new Serializer\CompactSerializer(), + new Serializer\JSONFlattenedSerializer(), + new Serializer\JSONGeneralSerializer(), ]); } diff --git a/src/SignatureAlgorithm/ECDSA/Tests/ECDSAFromRFC7520Test.php b/src/SignatureAlgorithm/ECDSA/Tests/ECDSAFromRFC7520Test.php index 52993768..b46cbc40 100644 --- a/src/SignatureAlgorithm/ECDSA/Tests/ECDSAFromRFC7520Test.php +++ b/src/SignatureAlgorithm/ECDSA/Tests/ECDSAFromRFC7520Test.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Algorithm\Tests; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm\ES512; use Jose\Component\Signature\JWSBuilder; @@ -66,20 +65,16 @@ public function eS512() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new ES512()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new ES512()]) ); $compactSerializer = new Serializer\CompactSerializer( - new StandardConverter() ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload) diff --git a/src/SignatureAlgorithm/EdDSA/Tests/EdDSASignatureTest.php b/src/SignatureAlgorithm/EdDSA/Tests/EdDSASignatureTest.php index eb4eb735..dbf6518a 100644 --- a/src/SignatureAlgorithm/EdDSA/Tests/EdDSASignatureTest.php +++ b/src/SignatureAlgorithm/EdDSA/Tests/EdDSASignatureTest.php @@ -15,7 +15,6 @@ use Base64Url\Base64Url; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm\EdDSA; use Jose\Component\Signature\JWS; @@ -71,14 +70,12 @@ public function edDSASignAndVerifyAlgorithm() $input = Base64Url::decode('RXhhbXBsZSBvZiBFZDI1NTE5IHNpZ25pbmc'); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new EdDSA()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new EdDSA()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($input) diff --git a/src/SignatureAlgorithm/HMAC/Tests/HMACFromRFC7520Test.php b/src/SignatureAlgorithm/HMAC/Tests/HMACFromRFC7520Test.php index 3be38ebe..8dcd4eb0 100644 --- a/src/SignatureAlgorithm/HMAC/Tests/HMACFromRFC7520Test.php +++ b/src/SignatureAlgorithm/HMAC/Tests/HMACFromRFC7520Test.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Algorithm\Tests; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm\HS256; use Jose\Component\Signature\JWSBuilder; @@ -65,20 +64,16 @@ public function hS256() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new HS256()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new HS256()]) ); $compactSerializer = new Serializer\CompactSerializer( - new StandardConverter() ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload) @@ -141,20 +136,16 @@ public function hS256WithDetachedPayload() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new HS256()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new HS256()]) ); $compactSerializer = new Serializer\CompactSerializer( - new StandardConverter() ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload, true) @@ -220,20 +211,16 @@ public function hS256WithUnprotectedHeader() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new HS256()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new HS256()]) ); $compactSerializer = new Serializer\CompactSerializer( - new StandardConverter() ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload) @@ -290,17 +277,14 @@ public function hS256WithoutProtectedHeader() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new HS256()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new HS256()]) ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload) diff --git a/src/SignatureAlgorithm/None/Tests/NoneSignatureTest.php b/src/SignatureAlgorithm/None/Tests/NoneSignatureTest.php index d83f8d35..489b12bf 100644 --- a/src/SignatureAlgorithm/None/Tests/NoneSignatureTest.php +++ b/src/SignatureAlgorithm/None/Tests/NoneSignatureTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Algorithm\Tests; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm\None; use Jose\Component\Signature\JWS; @@ -74,11 +73,9 @@ public function noneSignAndVerifyComplete() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new None()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.') diff --git a/src/SignatureAlgorithm/RSA/Tests/RSA15SignatureTest.php b/src/SignatureAlgorithm/RSA/Tests/RSA15SignatureTest.php index 5e8165dc..6004d0b1 100644 --- a/src/SignatureAlgorithm/RSA/Tests/RSA15SignatureTest.php +++ b/src/SignatureAlgorithm/RSA/Tests/RSA15SignatureTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Algorithm\Tests; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm\RS256; use Jose\Component\Signature\JWSBuilder; @@ -65,20 +64,16 @@ public function rS256() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new RS256()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new RS256()]) ); $compactSerializer = new Serializer\CompactSerializer( - new StandardConverter() ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload) diff --git a/src/SignatureAlgorithm/RSA/Tests/RSAKeyWithoutAllPrimesTest.php b/src/SignatureAlgorithm/RSA/Tests/RSAKeyWithoutAllPrimesTest.php index 1b7d8c10..4e662df6 100644 --- a/src/SignatureAlgorithm/RSA/Tests/RSAKeyWithoutAllPrimesTest.php +++ b/src/SignatureAlgorithm/RSA/Tests/RSAKeyWithoutAllPrimesTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Algorithm\Tests; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm; use Jose\Component\Signature\JWS; @@ -42,14 +41,12 @@ public function signatureAlgorithms(string $signature_algorithm) $claims = \json_encode(['foo' => 'bar']); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([$algorithm]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([$algorithm]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($claims) diff --git a/src/SignatureAlgorithm/RSA/Tests/RSAPSSSignatureTest.php b/src/SignatureAlgorithm/RSA/Tests/RSAPSSSignatureTest.php index 48961288..704992b7 100644 --- a/src/SignatureAlgorithm/RSA/Tests/RSAPSSSignatureTest.php +++ b/src/SignatureAlgorithm/RSA/Tests/RSAPSSSignatureTest.php @@ -14,7 +14,6 @@ namespace Jose\Component\Signature\Algorithm\Tests; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Signature\Algorithm\PS384; use Jose\Component\Signature\JWSBuilder; @@ -70,20 +69,16 @@ public function pS384() ]; $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new PS384()]) ); $jwsVerifier = new JWSVerifier( new AlgorithmManager([new PS384()]) ); $compactSerializer = new Serializer\CompactSerializer( - new StandardConverter() ); $jsonFlattenedSerializer = new Serializer\JSONFlattenedSerializer( - new StandardConverter() ); $jsonGeneralSerializer = new Serializer\JSONGeneralSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload($payload) diff --git a/src/SignatureAlgorithm/RSA/Tests/RSASignatureTest.php b/src/SignatureAlgorithm/RSA/Tests/RSASignatureTest.php index ad5a7b8c..ffc28e62 100644 --- a/src/SignatureAlgorithm/RSA/Tests/RSASignatureTest.php +++ b/src/SignatureAlgorithm/RSA/Tests/RSASignatureTest.php @@ -15,7 +15,6 @@ use Base64Url\Base64Url; use Jose\Component\Core\AlgorithmManager; -use Jose\Component\Core\Converter\StandardConverter; use Jose\Component\Core\JWK; use Jose\Component\Core\JWKSet; use Jose\Component\Signature\Algorithm; @@ -50,11 +49,9 @@ public function completeRS256Sign() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\RS256()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jwsBuilder = $jwsBuilder->create(['RS256']); $jws = $jwsBuilder @@ -99,11 +96,9 @@ public function completeRS256SignWithDetachedPayload() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\RS256()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.', true) @@ -147,11 +142,9 @@ public function completeRS384Sign() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\RS384()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.') @@ -195,11 +188,9 @@ public function completeRS512Sign() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\RS512()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.') @@ -245,11 +236,9 @@ public function completePS256Sign() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\PS256()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.') @@ -293,11 +282,9 @@ public function completePS384Sign() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\PS384()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.') @@ -340,11 +327,9 @@ public function completePS512Sign() ]); $jwsBuilder = new JWSBuilder( - new StandardConverter(), new AlgorithmManager([new Algorithm\PS512()]) ); $serializer = new CompactSerializer( - new StandardConverter() ); $jws = $jwsBuilder ->create()->withPayload('Live long and Prosper.') @@ -377,7 +362,6 @@ public function completePS512Sign() public function loadJWSJSONSerialization() { $serializer = new JSONGeneralSerializer( - new StandardConverter() ); $result = $serializer->unserialize('{"payload":"eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ","signatures":[{"protected":"eyJhbGciOiJSUzI1NiJ9","header":{"kid":"2010-12-29"},"signature":"cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"},{"protected":"eyJhbGciOiJFUzI1NiJ9","header":{"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"},"signature":"DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"}]}'); @@ -400,7 +384,6 @@ public function loadJWSJSONSerializationWithDetachedPayload() new AlgorithmManager([new Algorithm\RS256()]) ); $serializer = new JSONGeneralSerializer( - new StandardConverter() ); $result = $serializer->unserialize('{"signatures":[{"protected":"eyJhbGciOiJSUzI1NiJ9","header":{"kid":"2010-12-29"},"signature":"cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"},{"protected":"eyJhbGciOiJFUzI1NiJ9","header":{"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"},"signature":"DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"}]}'); @@ -423,7 +406,6 @@ public function loadJWSJSONSerializationWithDetachedPayloadAndPayloadInJWS() new AlgorithmManager([new Algorithm\RS256()]) ); $serializer = new JSONGeneralSerializer( - new StandardConverter() ); $result = $serializer->unserialize('{"payload":"eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ","signatures":[{"protected":"eyJhbGciOiJSUzI1NiJ9","header":{"kid":"2010-12-29"},"signature":"cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"},{"protected":"eyJhbGciOiJFUzI1NiJ9","header":{"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"},"signature":"DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"}]}'); @@ -443,7 +425,6 @@ public function loadJWSJSONSerializationWithDetachedPayloadAndPayloadInJWS() public function loadInvalidInput() { $serializer = new CompactSerializer( - new StandardConverter() ); $serializer->unserialize('DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q'); } @@ -457,7 +438,6 @@ public function loadInvalidInput() public function loadInvalidInput2() { $serializer = new CompactSerializer( - new StandardConverter() ); $serializer->unserialize('DtEhU3ljb.Eg8L.38VWAf.UAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q'); } @@ -470,7 +450,6 @@ public function loadInvalidInput2() public function loadIETFExample1() { $serializer = new CompactSerializer( - new StandardConverter() ); $result = $serializer->unserialize('eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk'); @@ -488,7 +467,6 @@ public function loadIETFExample1() public function loadIETFExample2() { $serializer = new CompactSerializer( - new StandardConverter() ); $result = $serializer->unserialize('eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw'); @@ -506,7 +484,6 @@ public function loadIETFExample2() public function loadIETFExample3() { $serializer = new CompactSerializer( - new StandardConverter() ); $result = $serializer->unserialize('eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q'); @@ -524,7 +501,6 @@ public function loadIETFExample3() public function loadIETFExample4() { $serializer = new CompactSerializer( - new StandardConverter() ); $result = $serializer->unserialize('eyJhbGciOiJFUzUxMiJ9.UGF5bG9hZA.AdwMgeerwtHoh-l192l60hp9wAHZFVJbLfD_UxMi70cwnZOYaRI1bKPWROc-mZZqwqT2SI-KGDKB34XO0aw_7XdtAG8GaSwFKdCAPZgoXD2YBJZCPEX3xKpRwcdOO8KpEHwJjyqOgzDO7iKvU8vcnwNrmxYbSW9ERBXukOXolLzeO_Jn');