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.
Completed
Push — master ( 59f4b4...e271c1 )
by Joni
03:51
created

SignatureAlgorithm::fromJWK()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWS;
6
7
use Sop\JWX\JWK\JWK;
8
use Sop\JWX\JWS\Algorithm\SignatureAlgorithmFactory;
9
use Sop\JWX\JWT\Header\Header;
10
use Sop\JWX\JWT\Header\HeaderParameters;
11
use Sop\JWX\JWT\Parameter\AlgorithmParameterValue;
12
use Sop\JWX\JWT\Parameter\KeyIDParameter;
13
14
/**
15
 * Base class for algorithms usable for signing and validating JWS's.
16
 */
17
abstract class SignatureAlgorithm implements AlgorithmParameterValue, HeaderParameters
18
{
19
    /**
20
     * ID of the key used by the algorithm.
21
     *
22
     * If set, KeyID parameter shall be automatically inserted into JWS's
23
     * header.
24
     *
25
     * @var null|string
26
     */
27
    protected $_keyID;
28
29
    /**
30
     * Compute signature.
31
     *
32
     * @param string $data Data for which the signature is computed
33
     *
34
     * @return string
35
     */
36
    abstract public function computeSignature(string $data): string;
37
38
    /**
39
     * Validate signature.
40
     *
41
     * @param string $data      Data to validate
42
     * @param string $signature Signature to compare
43
     *
44
     * @return bool
45
     */
46
    abstract public function validateSignature(string $data, string $signature): bool;
47
48
    /**
49
     * Initialize signature algorithm from a JWK and a header.
50
     *
51
     * @param JWK    $jwk    JSON Web Key
52
     * @param Header $header Header
53
     *
54
     * @return SignatureAlgorithm
55
     */
56 5
    public static function fromJWK(JWK $jwk, Header $header): SignatureAlgorithm
57
    {
58 5
        $factory = new SignatureAlgorithmFactory($header);
59 5
        return $factory->algoByKey($jwk);
60
    }
61
62
    /**
63
     * Get self with key ID.
64
     *
65
     * @param null|string $id Key ID or null to remove
66
     *
67
     * @return self
68
     */
69 2
    public function withKeyID(?string $id): self
70
    {
71 2
        $obj = clone $this;
72 2
        $obj->_keyID = $id;
73 2
        return $obj;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 18
    public function headerParameters(): array
80
    {
81 18
        $params = [];
82 18
        if (isset($this->_keyID)) {
83 2
            $params[] = new KeyIDParameter($this->_keyID);
84
        }
85 18
        return $params;
86
    }
87
}
88