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.

EncryptionVerifier::verify()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
rs 9.0534
cc 4
eloc 11
nc 4
nop 1
1
<?php
2
3
namespace Emarref\Jwt\Verification;
4
5
use Emarref\Jwt\Encoding;
6
use Emarref\Jwt\Encryption;
7
use Emarref\Jwt\Exception\InvalidSignatureException;
8
use Emarref\Jwt\HeaderParameter;
9
use Emarref\Jwt\Signature;
10
use Emarref\Jwt\Token;
11
12
class EncryptionVerifier implements VerifierInterface
13
{
14
    /**
15
     * @var Encryption\EncryptionInterface
16
     */
17
    private $encryption;
18
19
    /**
20
     * @var Encoding\EncoderInterface
21
     */
22
    private $encoder;
23
24
    /**
25
     * @var Signature\Jws
26
     */
27
    protected $signer;
28
29
    /**
30
     * @param Encryption\EncryptionInterface $encryption
31
     * @param Encoding\EncoderInterface    $encoder
32
     */
33
    public function __construct(Encryption\EncryptionInterface $encryption, Encoding\EncoderInterface $encoder)
34
    {
35
        $this->encryption = $encryption;
36
        $this->encoder    = $encoder;
37
        $this->signer     = new Signature\Jws($this->encryption, $this->encoder);
38
    }
39
40
    /**
41
     * @param Token $token
42
     * @throws InvalidSignatureException
43
     */
44
    public function verify(Token $token)
45
    {
46
        /** @var HeaderParameter\Algorithm $algorithmParameter */
47
        $algorithmParameter = $token->getHeader()->findParameterByName(HeaderParameter\Algorithm::NAME);
48
49
        if (null === $algorithmParameter) {
50
            throw new \RuntimeException('Algorithm parameter not found in token header.');
51
        }
52
53
        if ($algorithmParameter->getValue() !== $this->encryption->getAlgorithmName()) {
54
            throw new \RuntimeException(sprintf(
55
                'Cannot use "%s" algorithm to decrypt token encrypted with algorithm "%s".',
56
                $this->encryption->getAlgorithmName(),
57
                $algorithmParameter->getValue()
58
            ));
59
        }
60
61
        if (!$this->encryption->verify($this->signer->getUnsignedValue($token), $token->getSignature())) {
62
            throw new InvalidSignatureException;
63
        }
64
    }
65
}
66