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.

RSA   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sign() 0 17 2
A verify() 0 6 1
A extractPublicKeyFromPrivateKeyFile() 0 17 2
1
<?php
2
3
namespace Gandung\JWT\Algorithm;
4
5
use Gandung\JWT\SignerInterface;
6
use Gandung\JWT\Manager\KeyManagerInterface;
7
8
/**
9
 * @author Paulus Gandung Prakosa <[email protected]>
10
 */
11
abstract class RSA implements SignerInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function sign($payload, KeyManagerInterface $key)
17
    {
18
        $priv = \openssl_get_privatekey(
19
            $key->getContent(),
20
            $key->getPassphrase()
21
        );
22
23
        if (false === $priv) {
24
            throw new \RuntimeException(
25
                sprintf("Error: %s\n", \openssl_error_string())
26
            );
27
        }
28
29
        \openssl_sign($payload, $signature, $priv, $this->getAlgorithm());
30
31
        return $signature;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function verify($expected, $payload, KeyManagerInterface $key)
38
    {
39
        $pub = $this->extractPublicKeyFromPrivateKeyFile($key);
40
41
        return \openssl_verify($payload, $expected, $pub, $this->getAlgorithm()) === 1;
42
    }
43
44
    /**
45
     * Extract public key from private key file.
46
     *
47
     * @param string $key
48
     */
49
    private function extractPublicKeyFromPrivateKeyFile(KeyManagerInterface $key)
50
    {
51
        $priv = \openssl_get_privatekey(
52
            $key->getContent(),
53
            $key->getPassphrase()
54
        );
55
56
        if (false === $priv) {
57
            throw new \RuntimeException(
58
                sprintf("Failed to get private key object: %s\n", \openssl_error_string())
59
            );
60
        }
61
62
        $details = \openssl_pkey_get_details($priv);
63
64
        return $details['key'];
65
    }
66
}
67