Completed
Push — master ( de1564...663938 )
by Florent
10:19
created

RandomECKey   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 4 1
A addConfiguration() 0 15 1
A checkCurve() 0 6 1
A getKeyConfig() 0 8 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSource;
13
14
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15
16
class RandomECKey extends RandomKey
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function getKeyConfig(array $config)
22
    {
23
        $values = $config['additional_values'];
24
        $values['kty'] = 'EC';
25
        $values['crv'] = $config['curve'];
26
27
        return $values;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getKey()
34
    {
35
        return 'ec';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function addConfiguration(NodeDefinition $node)
42
    {
43
        
44
        $node
45
            ->children()
46
                ->scalarNode('curve')
47
                    ->validate()
48
                        ->ifTrue(self::checkCurve())
49
                        ->thenInvalid('Unsupported curve. Please use "P-256", "P-384" or "P-521".')
50
                    ->end()
51
                    ->isRequired()
52
                ->end()
53
            ->end();
54
        parent::addConfiguration($node);
55
    }
56
    
57
    private static function checkCurve()
58
    {
59
        return function ($v) {
60
            return !in_array($v, ['P-256', 'P-384', 'P-521']);
61
        };
62
    }
63
}
64