Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Console/RsaKeysetGeneratorCommand.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Console;
6
7 use InvalidArgumentException;
8 use Jose\Component\Core\JWKSet;
9 use Jose\Component\KeyManagement\JWKFactory;
10 use Symfony\Component\Console\Attribute\AsCommand;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14
15 #[AsCommand(name: 'keyset:generate:rsa', description: 'Generate a key set with RSA keys (JWK format)',)]
16 final class RsaKeysetGeneratorCommand extends GeneratorCommand
17 {
18 protected static $defaultName = 'keyset:generate:rsa';
19
20 protected static $defaultDescription = 'Generate a key set with RSA keys (JWK format)';
21
22 protected function configure(): void
23 {
24 parent::configure();
25 $this->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of keys in the key set.')
26 ->addArgument('size', InputArgument::REQUIRED, 'Key size.');
27 }
28
29 protected function execute(InputInterface $input, OutputInterface $output): int
30 {
31 $quantity = (int) $input->getArgument('quantity');
32 $size = (int) $input->getArgument('size');
33 if ($quantity < 1) {
34 throw new InvalidArgumentException('Invalid quantity');
35 }
36 if ($size < 1) {
37 throw new InvalidArgumentException('Invalid size');
38 }
39
40 $keyset = new JWKSet([]);
41 for ($i = 0; $i < $quantity; ++$i) {
42 $args = $this->getOptions($input);
43 $keyset = $keyset->with(JWKFactory::createRSAKey($size, $args));
44 }
45 $this->prepareJsonOutput($input, $output, $keyset);
46
47 return self::SUCCESS;
48 }
49 }