- md5
- 008e6657065c57a23dc6fef9f29c510d
- sha1
- a62d23ef81f7a2d8b99d66ce724440a83a709ccd
- sha256
- 281f7ab4c45fbf0877d7aa2cba7ae4d4faf775ddb9ed2af2c13220d2bffd10f2
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
<?php
declare(strict_types=1);
namespace Jose\Component\Console;
use InvalidArgumentException;
use Jose\Component\Core\Util\Base64UrlSafe;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use function is_bool;
abstract class GeneratorCommand extends ObjectOutputCommand
{
public function isEnabled(): bool
{
return class_exists(JWKFactory::class);
}
protected function configure(): void
{
parent::configure();
$this
->addOption('use', 'u', InputOption::VALUE_OPTIONAL, 'Usage of the key. Must be either "sig" or "enc".')
->addOption('alg', 'a', InputOption::VALUE_OPTIONAL, 'Algorithm for the key.')
->addOption(
'random_id',
null,
InputOption::VALUE_NONE,
'If this option is set, a random key ID (kid) will be generated.'
);
}
protected function getOptions(InputInterface $input): array
{
$args = [];
$useRandomId = $input->getOption('random_id');
if (! is_bool($useRandomId)) {
throw new InvalidArgumentException('Invalid value for option "random_id"');
}
if ($useRandomId) {
$args['kid'] = $this->generateKeyID();
}
foreach (['use', 'alg'] as $key) {
$value = $input->getOption($key);
if ($value !== null) {
$args[$key] = $value;
}
}
return $args;
}
private function generateKeyID(): string
{
return Base64UrlSafe::encode(random_bytes(32));
}
}
The same content is in 116 releases, Joomla 5.2.0-beta1 to 6.2.1. See them all, or every version of this file.