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

RandomOKPKey::getKeyConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 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 RandomOKPKey extends RandomKey
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function getKeyConfig(array $config)
22
    {
23
        $values = $config['additional_values'];
24
        $values['kty'] = 'OKP';
25
        $values['crv'] = $config['curve'];
26
27
        return $values;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getKey()
34
    {
35
        return 'okp';
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function addConfiguration(NodeDefinition $node)
42
    {
43
        $node
44
            ->children()
45
                ->scalarNode('curve')
46
                    ->validate()
47
                        ->ifTrue(self::checkCurve())
48
                        ->thenInvalid('Unsupported curve. Please use "X25519" or "Ed25519".')
49
                    ->end()
50
                    ->isRequired()
51
                ->end()
52
            ->end();
53
        parent::addConfiguration($node);
54
    }
55
56
    private static function checkCurve()
57
    {
58
        return function ($v) {
59
            return !in_array($v, ['X25519', 'Ed25519']);
60
        };
61
    }
62
}
63