Failed Conditions
Push — v7 ( 896db9...bffd87 )
by Florent
03:38
created

GeneratorPoint::isValid()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 13
nc 4
nop 2
1
<?php
2
3
namespace Jose\Component\Core\Util\Ecc\Primitives;
4
5
use Jose\Component\Core\Util\Ecc\Crypto\Key\PrivateKey;
6
use Jose\Component\Core\Util\Ecc\Crypto\Key\PublicKey;
7
8
/**
9
 * Curve point from which public and private keys can be derived.
10
 */
11
final class GeneratorPoint extends Point
12
{
13
    /**
14
     * @param CurveFp $curve
15
     * @param \GMP    $x
16
     * @param \GMP    $y
17
     * @param \GMP    $order
18
     */
19
    public function __construct(CurveFp $curve, \GMP $x, \GMP $y, \GMP $order)
20
    {
21
        parent::__construct($curve, $x, $y, $order);
22
    }
23
24
    /**
25
     * @param \GMP $x
26
     * @param \GMP $y
27
     * @param \GMP $order
28
     * @return PublicKey
29
     */
30
    public function getPublicKeyFrom(\GMP $x, \GMP $y, ?\GMP $order = null): PublicKey
31
    {
32
        $pubPoint = $this->getCurve()->getPoint($x, $y, $order);
33
        return new PublicKey($this, $pubPoint);
34
    }
35
36
    /**
37
     * @param \GMP $secret
38
     * @return PrivateKey
39
     */
40
    public function getPrivateKeyFrom(\GMP $secret): PrivateKey
41
    {
42
        return new PrivateKey($secret);
43
    }
44
}
45