Failed Conditions
Push — v7 ( a687dc...e264c8 )
by Florent
02:28
created

CurveFactory::getNistFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Jose\Component\Core\Util\Ecc\Curves;
4
5
use Jose\Component\Core\Util\Ecc\Math\GmpMath;
6
use Jose\Component\Core\Util\Ecc\Math\MathAdapterFactory;
7
use Jose\Component\Core\Util\Ecc\Primitives\CurveFp;
8
9
final class CurveFactory
10
{
11
    /**
12
     * @param $name
13
     * @return NamedCurveFp|CurveFp
14
     */
15
    public static function getCurveByName($name)
16
    {
17
        $adapter = MathAdapterFactory::getAdapter();
18
        $nistFactory = self::getNistFactory($adapter);
19
20
        switch ($name) {
21
            case NistCurve::NAME_P192:
22
                return $nistFactory->curve192();
0 ignored issues
show
Bug introduced by
The method curve192() does not seem to exist on object<Jose\Component\Co...l\Ecc\Curves\NistCurve>.

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...
23
            case NistCurve::NAME_P224:
24
                return $nistFactory->curve224();
0 ignored issues
show
Bug introduced by
The method curve224() does not seem to exist on object<Jose\Component\Co...l\Ecc\Curves\NistCurve>.

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...
25
            case NistCurve::NAME_P256:
26
                return $nistFactory->curve256();
27
            case NistCurve::NAME_P384:
28
                return $nistFactory->curve384();
29
            case NistCurve::NAME_P521:
30
                return $nistFactory->curve521();
31
            default:
32
                throw new \RuntimeException('Unknown curve.');
33
        }
34
    }
35
36
    /**
37
     * @param $name
38
     * @return \Jose\Component\Core\Util\Ecc\Primitives\GeneratorPoint
39
     */
40
    public static function getGeneratorByName($name)
41
    {
42
        $adapter = MathAdapterFactory::getAdapter();
43
        $nistFactory = self::getNistFactory($adapter);
44
45
        switch ($name) {
46
            case NistCurve::NAME_P192:
47
                return $nistFactory->generator192();
0 ignored issues
show
Bug introduced by
The method generator192() does not seem to exist on object<Jose\Component\Co...l\Ecc\Curves\NistCurve>.

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...
48
            case NistCurve::NAME_P224:
49
                return $nistFactory->generator224();
0 ignored issues
show
Bug introduced by
The method generator224() does not seem to exist on object<Jose\Component\Co...l\Ecc\Curves\NistCurve>.

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...
50
            case NistCurve::NAME_P256:
51
                return $nistFactory->generator256();
52
            case NistCurve::NAME_P384:
53
                return $nistFactory->generator384();
54
            case NistCurve::NAME_P521:
55
                return $nistFactory->generator521();
56
            default:
57
                throw new \RuntimeException('Unknown generator.');
58
        }
59
    }
60
61
    /**
62
     * @param GmpMath $math
63
     *
64
     * @return NistCurve
65
     */
66
    private static function getNistFactory(GmpMath $math): NistCurve
67
    {
68
        return new NistCurve($math);
69
    }
70
}
71