Failed Conditions
Push — v7 ( 12d27f...276ae4 )
by Florent
03:49
created

RsaKeysetGeneratorCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
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;
15
16
use Jose\Component\Core\JWKSet;
17
use Jose\Component\KeyManagement\JWKFactory;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Class RsaKeysetGeneratorCommand.
24
 */
25
final class RsaKeysetGeneratorCommand extends AbstractGeneratorCommand
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        parent::configure();
33
        $this
34
            ->setName('keyset:generate:rsa')
35
            ->setDescription('Generate a key set with RSA keys (JWK format)')
36
            ->addArgument('size', InputArgument::REQUIRED, 'Quantity of keys in the key set.')
37
            ->addArgument('curve', InputArgument::REQUIRED, 'Key size.');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $quantity = (int) $input->getArgument('quantity');
46
        $size = (int) $input->getArgument('size');
47
        $args = $this->getOptions($input);
48
49
        $keyset = JWKSet::createFromKeys([]);
50
        for ($i = 0; $i < $quantity; ++$i) {
51
            $keyset = $keyset->with(JWKFactory::createRSAKey($size, $args));
52
        }
53
        $this->prepareJsonOutput($input, $output, $keyset);
54
    }
55
}
56