S256Verifier::verifyCodeChallenge()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author      Lukáš Unger <[email protected]>
5
 * @copyright   Copyright (c) Lukáš Unger
6
 * @license     http://mit-license.org/
7
 *
8
 * @link        https://github.com/thephpleague/oauth2-server
9
 */
10
11
declare(strict_types=1);
12
13
namespace League\OAuth2\Server\CodeChallengeVerifiers;
14
15
use function base64_encode;
16
use function hash;
17
use function hash_equals;
18
use function rtrim;
19
use function strtr;
20
21
class S256Verifier implements CodeChallengeVerifierInterface
22
{
23
    /**
24
     * Return code challenge method.
25
     */
26 54
    public function getMethod(): string
27
    {
28 54
        return 'S256';
29
    }
30
31
    /**
32
     * Verify the code challenge.
33
     */
34 3
    public function verifyCodeChallenge(string $codeVerifier, string $codeChallenge): bool
35
    {
36 3
        return hash_equals(
37 3
            strtr(rtrim(base64_encode(hash('sha256', $codeVerifier, true)), '='), '+/', '-_'),
38 3
            $codeChallenge
39 3
        );
40
    }
41
}
42