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

P12CertificateLoaderCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 28
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 10 1
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\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
final class P12CertificateLoaderCommand extends AbstractGeneratorCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('key:load:p12')
31
            ->setDescription('Load a key from a P12 certificate file.')
32
            ->addArgument('file', InputArgument::REQUIRED, 'Filename of the P12 certificate.')
33
            ->addOption('secret', 's', InputOption::VALUE_OPTIONAL, 'Secret if the key is encrypted.', null);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $filename = $input->getArgument('file');
42
        $password = $input->getOption('secret');
43
        $args = $this->getOptions($input);
44
45
        $jwk = JWKFactory::createFromPKCS12CertificateFile($filename, $password, $args);
46
        $json = json_encode($jwk);
47
        $this->prepareOutput($input, $output, $json);
48
    }
49
}
50