-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEcKeysetGeneratorCommand.php
48 lines (40 loc) · 1.5 KB
/
EcKeysetGeneratorCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace Jose\Component\Console;
use InvalidArgumentException;
use function is_string;
use Jose\Component\Core\JWKSet;
use Jose\Component\KeyManagement\JWKFactory;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class EcKeysetGeneratorCommand extends GeneratorCommand
{
protected static $defaultName = 'keyset:generate:ec';
protected function configure(): void
{
parent::configure();
$this->setDescription('Generate an EC key set (JWKSet format)')
->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of keys in the key set.')
->addArgument('curve', InputArgument::REQUIRED, 'Curve of the keys.')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$quantity = (int) $input->getArgument('quantity');
if ($quantity < 1) {
throw new InvalidArgumentException('Invalid quantity');
}
$curve = $input->getArgument('curve');
if (! is_string($curve)) {
throw new InvalidArgumentException('Invalid curve');
}
$keyset = new JWKSet([]);
for ($i = 0; $i < $quantity; ++$i) {
$args = $this->getOptions($input);
$keyset = $keyset->with(JWKFactory::createECKey($curve, $args));
}
$this->prepareJsonOutput($input, $output, $keyset);
return 0;
}
}