Failed Conditions
Push — v7 ( 809898...b3c0a6 )
by Florent
05:05
created

X509CertificateLoaderCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 15
rs 9.4285
c 1
b 0
f 1
cc 3
eloc 10
nc 3
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\Command;
15
16
use Jose\Component\Core\JWKFactory;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
final class X509CertificateLoaderCommand extends AbstractGeneratorCommand
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function configure()
27
    {
28
        $this
29
            ->setName('key:load:x509')
30
            ->setDescription('Load a key from a X.509 certificate file.')
31
            ->addArgument('file', InputArgument::REQUIRED, 'Filename of the X.509 certificate.');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $filename = $input->getArgument('file');
40
        $args = [];
41
        foreach (['use', 'alg'] as $key) {
42
            $value = $input->getOption($key);
43
            if (null !== $value) {
44
                $args[$key] = $value;
45
            }
46
        }
47
48
        $jwk = JWKFactory::createFromCertificateFile($filename, $args);
49
        $json = json_encode($jwk);
50
        $this->prepareOutput($input, $output, $json);
51
    }
52
}
53