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 ( dca57d...79f563 )
by Malcolm
04:50 queued 02:15
created

Symmetric::setSecret()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Emarref\Jwt\Encryption;
4
5
use Emarref\Jwt\Algorithm;
6
7
/**
8
 * @property Algorithm\SymmetricInterface $algorithm
9
 */
10
class Symmetric extends AbstractEncryption implements EncryptionInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $secret;
16
17
    /**
18
     * @param Algorithm\SymmetricInterface $algorithm
19
     */
20
    public function __construct(Algorithm\SymmetricInterface $algorithm)
21
    {
22
        parent::__construct($algorithm);
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getSecret()
29
    {
30
        return $this->secret;
31
    }
32
33
    /**
34
     * @param string $secret
35
     * @return $this
36
     */
37
    public function setSecret($secret)
38
    {
39
        $this->secret = $secret;
40
        return $this;
41
    }
42
43
    /**
44
     * @param string $value
45
     * @return string
46
     */
47
    public function encrypt($value)
48
    {
49
        return $this->algorithm->compute($value);
50
    }
51
52
    /**
53
     * @param string $value
54
     * @param string $signature
55
     * @return boolean
56
     */
57
    public function verify($value, $signature)
58
    {
59
        $computedValue = $this->algorithm->compute($value);
60
61
        return $this->timingSafeEquals($signature, $computedValue);
62
    }
63
64
    /**
65
     * A timing safe equals comparison.
66
     *
67
     * @see http://blog.ircmaxell.com/2014/11/its-all-about-time.html
68
     *
69
     * @param string $safe The internal (safe) value to be checked
70
     * @param string $user The user submitted (unsafe) value
71
     *
72
     * @return boolean True if the two strings are identical.
73
     */
74
    public function timingSafeEquals($safe, $user)
75
    {
76
        if (function_exists('hash_equals')) {
77
            return hash_equals($user, $safe);
78
        }
79
80
        $safeLen = strlen($safe);
81
        $userLen = strlen($user);
82
83
        /*
84
         * In general, it's not possible to prevent length leaks. So it's OK to leak the length.
85
         * @see http://security.stackexchange.com/questions/49849/timing-safe-string-comparison-avoiding-length-leak
86
         */
87
        if ($userLen != $safeLen) {
88
            return false;
89
        }
90
91
        $result = 0;
92
93
        for ($i = 0; $i < $userLen; $i++) {
94
            $result |= (ord($safe[$i]) ^ ord($user[$i]));
95
        }
96
97
        return $result === 0;
98
    }
99
}
100