1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2017 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Component\Console\Command; |
15
|
|
|
|
16
|
|
|
use Jose\Component\Core\JWKSet; |
17
|
|
|
use Jose\Component\Core\JWKFactory; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
|
22
|
|
|
final class OctKeysetGeneratorCommand extends AbstractGeneratorCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected function configure() |
28
|
|
|
{ |
29
|
|
|
$this |
30
|
|
|
->setName('keyset:generate:oct') |
31
|
|
|
->setDescription('Generate a key set with octet keys (JWK format)') |
32
|
|
|
->addArgument('quantity', InputArgument::REQUIRED, 'Quantity of keys in the key set.') |
33
|
|
|
->addArgument('size', InputArgument::REQUIRED, 'Key size.'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
|
|
$quantity = (int) $input->getArgument('quantity'); |
42
|
|
|
$size = (int) $input->getArgument('size'); |
43
|
|
|
$args = $this->getOptions($input); |
44
|
|
|
|
45
|
|
|
$keyset = JWKSet::createFromKeys([]); |
46
|
|
|
for ($i = 0; $i < $quantity; ++$i) { |
47
|
|
|
$keyset = $keyset->withKey(JWKFactory::createOctKey($size, $args)); |
48
|
|
|
} |
49
|
|
|
$json = json_encode($keyset); |
50
|
|
|
$this->prepareOutput($input, $output, $json); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|