S256Verifier   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A verifyCodeChallenge() 0 5 1
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