GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ECDSA::sign()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Gandung\JWT\Algorithm;
4
5
use Gandung\JWT\Adapter\ECDSAAdapterInterface;
6
use Gandung\JWT\SignerInterface;
7
use Gandung\JWT\Manager\KeyManagerInterface;
8
use Mdanter\Ecc\Crypto\Key\PrivateKeyInterface;
9
use Mdanter\Ecc\Crypto\Key\PublicKeyInterface;
10
use Mdanter\Ecc\Serializer\PrivateKey\DerPrivateKeySerializer;
11
use Mdanter\Ecc\Serializer\PrivateKey\PemPrivateKeySerializer;
12
use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer;
13
use Mdanter\Ecc\Serializer\PublicKey\PemPublicKeySerializer;
14
15
/**
16
 * @author Paulus Gandung Prakosa <[email protected]>
17
 */
18
abstract class ECDSA implements SignerInterface
19
{
20
    /**
21
     * @var ECDSAAdapterInterface
22
     */
23
    private $adapter;
24
25
    /**
26
     * @var $private
27
     */
28
    private $private;
29
30
    /**
31
     * @var $public
32
     */
33
    private $public;
34
35
    public function __construct(ECDSAAdapterInterface $adapter)
36
    {
37
        $this->adapter = $adapter;
38
        $publicDer = new DerPublicKeySerializer($this->adapter->getMathAdapter());
39
        $this->public = new PemPublicKeySerializer($publicDer);
40
        $this->private = new PemPrivateKeySerializer(
41
            new DerPrivateKeySerializer($this->adapter->getMathAdapter(), $publicDer)
42
        );
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function sign($payload, KeyManagerInterface $key)
49
    {
50
        return $this->adapter->sign(
51
            $this->getPrivateKey($key),
52
            $this->adapter->createSigningHash($payload, $this->getAlgorithm()),
0 ignored issues
show
Bug introduced by
It seems like $payload defined by parameter $payload on line 48 can also be of type array; however, Gandung\JWT\Adapter\ECDS...ce::createSigningHash() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
53
            $this->getAlgorithm()
54
        );
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function verify($expected, $payload, KeyManagerInterface $key)
61
    {
62
        return $this->adapter->verify(
63
            $expected,
64
            $this->getPublicKey($key),
65
            $this->adapter->createSigningHash($payload, $this->getAlgorithm()),
0 ignored issues
show
Bug introduced by
It seems like $payload defined by parameter $payload on line 60 can also be of type array; however, Gandung\JWT\Adapter\ECDS...ce::createSigningHash() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
66
            $this->getAlgorithm()
67
        );
68
    }
69
70
    /**
71
     * Get private key object from given certificate.
72
     *
73
     * @param string $key
74
     * @return PrivateKeyInterface
75
     */
76
    public function getPrivateKey(KeyManagerInterface $key)
77
    {
78
        return $this->private->parse($key->getContent());
79
    }
80
81
    /**
82
     * Get public key object from given certificate.
83
     *
84
     * @param string $key
85
     * @return PublicKeyInterface
86
     */
87
    public function getPublicKey(KeyManagerInterface $key)
88
    {
89
        return $this->public->parse($key->getContent());
90
    }
91
}
92