Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Console/OkpKeysetGeneratorCommand.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 use function is_string;
15
16 #[AsCommand(
17 name: 'keyset:generate:okp',
18 description: 'Generate a key set with Octet Key Pairs keys (JWKSet format)',
19 )]
20 final class OkpKeysetGeneratorCommand extends GeneratorCommand
21 {
22 protected static $defaultName = 'keyset:generate:okp';
23
24 protected static $defaultDescription = 'Generate a key set with Octet Key Pairs keys (JWKSet format)';
25
26 protected function configure(): void
27 {
28 parent::configure();
29 $this->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of keys in the key set.')
30 ->addArgument('curve', InputArgument::REQUIRED, 'Curve of the keys.');
31 }
32
33 protected function execute(InputInterface $input, OutputInterface $output): int
34 {
35 $quantity = (int) $input->getArgument('quantity');
36 $curve = $input->getArgument('curve');
37 if ($quantity < 1) {
38 throw new InvalidArgumentException('Invalid quantity');
39 }
40 if (! is_string($curve)) {
41 throw new InvalidArgumentException('Invalid curve');
42 }
43
44 $keyset = new JWKSet([]);
45 for ($i = 0; $i < $quantity; ++$i) {
46 $args = $this->getOptions($input);
47 $keyset = $keyset->with(JWKFactory::createOKPKey($curve, $args));
48 }
49 $this->prepareJsonOutput($input, $output, $keyset);
50
51 return self::SUCCESS;
52 }
53 }