Completed
Push — master ( 7b61ef...71e756 )
by Florent
08:30 queued 07:08
created

P12::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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\Bundle\JoseFramework\DependencyInjection\Source\KeyManagement\JWKSource;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource;
17
use Jose\Component\KeyManagement\JWKFactory;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Reference;
22
23
class P12 extends AbstractSource implements JWKSource
24
{
25
    public function createDefinition(ContainerBuilder $container, array $config): Definition
26
    {
27
        $definition = new Definition(JWK::class);
28
        $definition->setFactory([
29
            new Reference(JWKFactory::class),
30
            'createFromPKCS12CertificateFile',
31
        ]);
32
        $definition->setArguments([
33
            $config['path'],
34
            $config['password'],
35
            $config['additional_values'],
36
        ]);
37
        $definition->addTag('jose.jwk');
38
39
        return $definition;
40
    }
41
42
    public function getKey(): string
43
    {
44
        return 'p12';
45
    }
46
47
    public function addConfiguration(NodeDefinition $node): void
48
    {
49
        parent::addConfiguration($node);
50
        $node
51
            ->children()
52
            ->scalarNode('path')
53
            ->info('Path of the key file.')
54
            ->isRequired()
55
            ->end()
56
            ->scalarNode('password')
57
            ->info('Password used to decrypt the key (optional).')
58
            ->defaultNull()
59
            ->end()
60
            ->arrayNode('additional_values')
61
            ->info('Additional values to be added to the key.')
62
            ->defaultValue([])
63
            ->useAttributeAsKey('key')
64
            ->variablePrototype()->end()
65
            ->end()
66
            ->end()
67
        ;
68
    }
69
}
70