Completed
Push — master ( 35e232...de1564 )
by Florent
02:34
created

RandomOKPKey   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createNewKey() 0 7 1
A getKey() 0 4 1
A addConfiguration() 0 14 1
A checkCurve() 0 6 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 Jose\Factory\JWKFactory;
15
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
16
17
class RandomOKPKey extends RandomKey
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected function createNewKey(array $config)
23
    {
24
        $curve = $config['curve'];
25
        $values = $config['additional_values'];
26
27
        return JWKFactory::createOKPKey($curve, $values)->getAll();
0 ignored issues
show
Bug introduced by
The method createOKPKey() does not seem to exist on object<Jose\Factory\JWKFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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