Completed
Push — master ( ff92f6...3ef1d3 )
by John
09:08
created

RsaValidator::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\JwtBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\JwtBundle\Jwt\SignatureValidator;
10
11
/**
12
 * @author John Kleijn <[email protected]>
13
 */
14
class RsaValidator implements SignatureValidator
15
{
16
    const SHA256 = OPENSSL_ALGO_SHA256;
17
    const SHA512 = OPENSSL_ALGO_SHA512;
18
19
    /**
20
     * @var int
21
     */
22
    private $hashAlgorithm;
23
24
    /**
25
     * @param int $hashAlgorithm
26
     */
27
    public function __construct($hashAlgorithm = self::SHA256)
28
    {
29
        $this->hashAlgorithm = $hashAlgorithm;
30
    }
31
32
    /**
33
     * @param string $payload
34
     * @param string $publicKey
35
     * @param string $signature
36
     *
37
     * @return bool
38
     */
39
    public function isValid($payload, $publicKey, $signature)
40
    {
41
        return openssl_verify($payload, $signature, $publicKey, $this->hashAlgorithm) === 1;
42
    }
43
}
44