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.
Passed
Push — php72 ( efc120...19e113 )
by Joni
02:36
created
lib/JWX/Parameter/Feature/Base64UIntValue.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,28 +15,28 @@
 block discarded – undo
15 15
  */
16 16
 trait Base64UIntValue
17 17
 {
18
-    use Base64URLValue;
18
+	use Base64URLValue;
19 19
 
20
-    /**
21
-     * Initialize parameter from base10 number.
22
-     *
23
-     * @param int|string $number
24
-     *
25
-     * @return self
26
-     */
27
-    public static function fromNumber($number): Parameter
28
-    {
29
-        $data = BigInt::fromBase10($number)->base256();
30
-        return static::fromString($data);
31
-    }
20
+	/**
21
+	 * Initialize parameter from base10 number.
22
+	 *
23
+	 * @param int|string $number
24
+	 *
25
+	 * @return self
26
+	 */
27
+	public static function fromNumber($number): Parameter
28
+	{
29
+		$data = BigInt::fromBase10($number)->base256();
30
+		return static::fromString($data);
31
+	}
32 32
 
33
-    /**
34
-     * Get value as a number.
35
-     *
36
-     * @return BigInt
37
-     */
38
-    public function number(): BigInt
39
-    {
40
-        return BigInt::fromBase256(Base64::urlDecode($this->value()));
41
-    }
33
+	/**
34
+	 * Get value as a number.
35
+	 *
36
+	 * @return BigInt
37
+	 */
38
+	public function number(): BigInt
39
+	{
40
+		return BigInt::fromBase256(Base64::urlDecode($this->value()));
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\Parameter\Feature;
6 6
 
Please login to merge, or discard this patch.
lib/JWX/JWE/EncryptionAlgorithm/A256GCMAlgorithm.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWE\EncryptionAlgorithm;
6 6
 
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@
 block discarded – undo
13 13
  */
14 14
 class A256GCMAlgorithm extends AESGCMAlgorithm
15 15
 {
16
-    /**
17
-     * {@inheritdoc}
18
-     */
19
-    public function encryptionAlgorithmParamValue(): string
20
-    {
21
-        return JWA::ALGO_A256GCM;
22
-    }
16
+	/**
17
+	 * {@inheritdoc}
18
+	 */
19
+	public function encryptionAlgorithmParamValue(): string
20
+	{
21
+		return JWA::ALGO_A256GCM;
22
+	}
23 23
 
24
-    /**
25
-     * {@inheritdoc}
26
-     */
27
-    public function keySize(): int
28
-    {
29
-        return 32;
30
-    }
24
+	/**
25
+	 * {@inheritdoc}
26
+	 */
27
+	public function keySize(): int
28
+	{
29
+		return 32;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
lib/JWX/JWE/EncryptionAlgorithm/A192GCMAlgorithm.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWE\EncryptionAlgorithm;
6 6
 
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@
 block discarded – undo
13 13
  */
14 14
 class A192GCMAlgorithm extends AESGCMAlgorithm
15 15
 {
16
-    /**
17
-     * {@inheritdoc}
18
-     */
19
-    public function encryptionAlgorithmParamValue(): string
20
-    {
21
-        return JWA::ALGO_A192GCM;
22
-    }
16
+	/**
17
+	 * {@inheritdoc}
18
+	 */
19
+	public function encryptionAlgorithmParamValue(): string
20
+	{
21
+		return JWA::ALGO_A192GCM;
22
+	}
23 23
 
24
-    /**
25
-     * {@inheritdoc}
26
-     */
27
-    public function keySize(): int
28
-    {
29
-        return 24;
30
-    }
24
+	/**
25
+	 * {@inheritdoc}
26
+	 */
27
+	public function keySize(): int
28
+	{
29
+		return 24;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
lib/JWX/JWE/EncryptionAlgorithm/AESGCMAlgorithm.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWE\EncryptionAlgorithm;
6 6
 
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -17,74 +17,74 @@
 block discarded – undo
17 17
  */
18 18
 abstract class AESGCMAlgorithm implements ContentEncryptionAlgorithm
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    public function encrypt(string $plaintext, string $key, string $iv,
24
-        string $aad): array
25
-    {
26
-        $this->_validateKey($key);
27
-        $this->_validateIV($iv);
28
-        return AESGCM::encrypt($plaintext, $aad, $key, $iv, 16);
29
-    }
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	public function encrypt(string $plaintext, string $key, string $iv,
24
+		string $aad): array
25
+	{
26
+		$this->_validateKey($key);
27
+		$this->_validateIV($iv);
28
+		return AESGCM::encrypt($plaintext, $aad, $key, $iv, 16);
29
+	}
30 30
 
31
-    /**
32
-     * {@inheritdoc}
33
-     */
34
-    public function decrypt(string $ciphertext, string $key, string $iv,
35
-        string $aad, string $auth_tag): string
36
-    {
37
-        $this->_validateKey($key);
38
-        $this->_validateIV($iv);
39
-        try {
40
-            $plaintext = AESGCM::decrypt($ciphertext, $auth_tag, $aad, $key, $iv);
41
-        } catch (GCMAuthException $e) {
42
-            throw new AuthenticationException('Message authentication failed.');
43
-        }
44
-        return $plaintext;
45
-    }
31
+	/**
32
+	 * {@inheritdoc}
33
+	 */
34
+	public function decrypt(string $ciphertext, string $key, string $iv,
35
+		string $aad, string $auth_tag): string
36
+	{
37
+		$this->_validateKey($key);
38
+		$this->_validateIV($iv);
39
+		try {
40
+			$plaintext = AESGCM::decrypt($ciphertext, $auth_tag, $aad, $key, $iv);
41
+		} catch (GCMAuthException $e) {
42
+			throw new AuthenticationException('Message authentication failed.');
43
+		}
44
+		return $plaintext;
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritdoc}
49
-     */
50
-    public function ivSize(): int
51
-    {
52
-        return 12;
53
-    }
47
+	/**
48
+	 * {@inheritdoc}
49
+	 */
50
+	public function ivSize(): int
51
+	{
52
+		return 12;
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritdoc}
57
-     */
58
-    public function headerParameters(): array
59
-    {
60
-        return [EncryptionAlgorithmParameter::fromAlgorithm($this)];
61
-    }
55
+	/**
56
+	 * {@inheritdoc}
57
+	 */
58
+	public function headerParameters(): array
59
+	{
60
+		return [EncryptionAlgorithmParameter::fromAlgorithm($this)];
61
+	}
62 62
 
63
-    /**
64
-     * Check that key is valid.
65
-     *
66
-     * @param string $key
67
-     *
68
-     * @throws \RuntimeException
69
-     */
70
-    final protected function _validateKey(string $key): void
71
-    {
72
-        if (strlen($key) !== $this->keySize()) {
73
-            throw new \RuntimeException('Invalid key size.');
74
-        }
75
-    }
63
+	/**
64
+	 * Check that key is valid.
65
+	 *
66
+	 * @param string $key
67
+	 *
68
+	 * @throws \RuntimeException
69
+	 */
70
+	final protected function _validateKey(string $key): void
71
+	{
72
+		if (strlen($key) !== $this->keySize()) {
73
+			throw new \RuntimeException('Invalid key size.');
74
+		}
75
+	}
76 76
 
77
-    /**
78
-     * Check that IV is valid.
79
-     *
80
-     * @param string $iv
81
-     *
82
-     * @throws \RuntimeException
83
-     */
84
-    final protected function _validateIV(string $iv): void
85
-    {
86
-        if (strlen($iv) !== $this->ivSize()) {
87
-            throw new \RuntimeException('Invalid IV length.');
88
-        }
89
-    }
77
+	/**
78
+	 * Check that IV is valid.
79
+	 *
80
+	 * @param string $iv
81
+	 *
82
+	 * @throws \RuntimeException
83
+	 */
84
+	final protected function _validateIV(string $iv): void
85
+	{
86
+		if (strlen($iv) !== $this->ivSize()) {
87
+			throw new \RuntimeException('Invalid IV length.');
88
+		}
89
+	}
90 90
 }
Please login to merge, or discard this patch.
lib/JWX/JWE/KeyAlgorithm/RSAESKeyAlgorithm.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\JWX\JWE\KeyAlgorithm;
6 6
 
Please login to merge, or discard this patch.
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -21,202 +21,202 @@
 block discarded – undo
21 21
  */
22 22
 abstract class RSAESKeyAlgorithm extends KeyManagementAlgorithm
23 23
 {
24
-    use RandomCEK;
25
-
26
-    /**
27
-     * Mapping from algorithm name to class name.
28
-     *
29
-     * @internal
30
-     *
31
-     * @var array
32
-     */
33
-    const MAP_ALGO_TO_CLASS = [
34
-        JWA::ALGO_RSA1_5 => RSAESPKCS1Algorithm::class,
35
-        JWA::ALGO_RSA_OAEP => RSAESOAEPAlgorithm::class,
36
-    ];
37
-
38
-    /**
39
-     * Public key.
40
-     *
41
-     * @var RSAPublicKeyJWK
42
-     */
43
-    protected $_publicKey;
44
-
45
-    /**
46
-     * Private key.
47
-     *
48
-     * @var null|RSAPrivateKeyJWK
49
-     */
50
-    protected $_privateKey;
51
-
52
-    /**
53
-     * Constructor.
54
-     *
55
-     * Use `fromPublicKey` or `fromPrivateKey` instead!
56
-     *
57
-     * @param RSAPublicKeyJWK  $pub_key  RSA public key
58
-     * @param RSAPrivateKeyJWK $priv_key Optional RSA private key
59
-     */
60
-    protected function __construct(RSAPublicKeyJWK $pub_key,
61
-        ?RSAPrivateKeyJWK $priv_key = null)
62
-    {
63
-        $this->_publicKey = $pub_key;
64
-        $this->_privateKey = $priv_key;
65
-    }
66
-
67
-    /**
68
-     * Initialize from JWK.
69
-     *
70
-     * @param JWK    $jwk
71
-     * @param Header $header
72
-     *
73
-     * @throws \UnexpectedValueException
74
-     *
75
-     * @return self
76
-     */
77
-    public static function fromJWK(JWK $jwk, Header $header): KeyManagementAlgorithm
78
-    {
79
-        $alg = JWA::deriveAlgorithmName($header, $jwk);
80
-        if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) {
81
-            throw new \UnexpectedValueException("Unsupported algorithm '{$alg}'.");
82
-        }
83
-        $cls = self::MAP_ALGO_TO_CLASS[$alg];
84
-        if ($jwk->has(...RSAPrivateKeyJWK::MANAGED_PARAMS)) {
85
-            return $cls::fromPrivateKey(RSAPrivateKeyJWK::fromJWK($jwk));
86
-        }
87
-        return $cls::fromPublicKey(RSAPublicKeyJWK::fromJWK($jwk));
88
-    }
89
-
90
-    /**
91
-     * Initialize from a public key.
92
-     *
93
-     * @param RSAPublicKeyJWK $jwk
94
-     *
95
-     * @return self
96
-     */
97
-    public static function fromPublicKey(RSAPublicKeyJWK $jwk): self
98
-    {
99
-        return new static($jwk);
100
-    }
101
-
102
-    /**
103
-     * Initialize from a private key.
104
-     *
105
-     * @param RSAPrivateKeyJWK $jwk
106
-     *
107
-     * @return self
108
-     */
109
-    public static function fromPrivateKey(RSAPrivateKeyJWK $jwk): self
110
-    {
111
-        return new static($jwk->publicKey(), $jwk);
112
-    }
113
-
114
-    /**
115
-     * Get the public key.
116
-     *
117
-     * @return RSAPublicKeyJWK
118
-     */
119
-    public function publicKey(): RSAPublicKeyJWK
120
-    {
121
-        return $this->_publicKey;
122
-    }
123
-
124
-    /**
125
-     * Check whether the private key is present.
126
-     *
127
-     * @return bool
128
-     */
129
-    public function hasPrivateKey(): bool
130
-    {
131
-        return isset($this->_privateKey);
132
-    }
133
-
134
-    /**
135
-     * Get the private key.
136
-     *
137
-     * @throws \LogicException
138
-     *
139
-     * @return RSAPrivateKeyJWK
140
-     */
141
-    public function privateKey(): RSAPrivateKeyJWK
142
-    {
143
-        if (!$this->hasPrivateKey()) {
144
-            throw new \LogicException('Private key not set.');
145
-        }
146
-        return $this->_privateKey;
147
-    }
148
-
149
-    /**
150
-     * {@inheritdoc}
151
-     */
152
-    public function headerParameters(): array
153
-    {
154
-        return array_merge(parent::headerParameters(),
155
-            [AlgorithmParameter::fromAlgorithm($this)]);
156
-    }
157
-
158
-    /**
159
-     * Get the padding scheme.
160
-     *
161
-     * @return int
162
-     */
163
-    abstract protected function _paddingScheme(): int;
164
-
165
-    /**
166
-     * {@inheritdoc}
167
-     */
168
-    protected function _encryptKey(string $key, Header &$header): string
169
-    {
170
-        $pubkey = openssl_pkey_get_public(
171
-            $this->publicKey()->toPEM()->string());
172
-        if (false === $pubkey) {
173
-            throw new \RuntimeException(
174
-                'openssl_pkey_get_public() failed: ' .
175
-                     $this->_getLastOpenSSLError());
176
-        }
177
-        $result = openssl_public_encrypt($key, $crypted, $pubkey,
178
-            $this->_paddingScheme());
179
-        if (!$result) {
180
-            throw new \RuntimeException(
181
-                'openssl_public_encrypt() failed: ' .
182
-                     $this->_getLastOpenSSLError());
183
-        }
184
-        return $crypted;
185
-    }
186
-
187
-    /**
188
-     * {@inheritdoc}
189
-     */
190
-    protected function _decryptKey(string $ciphertext, Header $header): string
191
-    {
192
-        $privkey = openssl_pkey_get_private(
193
-            $this->privateKey()->toPEM()->string());
194
-        if (false === $privkey) {
195
-            throw new \RuntimeException(
196
-                'openssl_pkey_get_private() failed: ' .
197
-                     $this->_getLastOpenSSLError());
198
-        }
199
-        $result = openssl_private_decrypt($ciphertext, $cek, $privkey,
200
-            $this->_paddingScheme());
201
-        if (!$result) {
202
-            throw new \RuntimeException(
203
-                'openssl_private_decrypt() failed: ' .
204
-                     $this->_getLastOpenSSLError());
205
-        }
206
-        return $cek;
207
-    }
208
-
209
-    /**
210
-     * Get last OpenSSL error message.
211
-     *
212
-     * @return null|string
213
-     */
214
-    protected function _getLastOpenSSLError(): ?string
215
-    {
216
-        $msg = null;
217
-        while (false !== ($err = openssl_error_string())) {
218
-            $msg = $err;
219
-        }
220
-        return $msg;
221
-    }
24
+	use RandomCEK;
25
+
26
+	/**
27
+	 * Mapping from algorithm name to class name.
28
+	 *
29
+	 * @internal
30
+	 *
31
+	 * @var array
32
+	 */
33
+	const MAP_ALGO_TO_CLASS = [
34
+		JWA::ALGO_RSA1_5 => RSAESPKCS1Algorithm::class,
35
+		JWA::ALGO_RSA_OAEP => RSAESOAEPAlgorithm::class,
36
+	];
37
+
38
+	/**
39
+	 * Public key.
40
+	 *
41
+	 * @var RSAPublicKeyJWK
42
+	 */
43
+	protected $_publicKey;
44
+
45
+	/**
46
+	 * Private key.
47
+	 *
48
+	 * @var null|RSAPrivateKeyJWK
49
+	 */
50
+	protected $_privateKey;
51
+
52
+	/**
53
+	 * Constructor.
54
+	 *
55
+	 * Use `fromPublicKey` or `fromPrivateKey` instead!
56
+	 *
57
+	 * @param RSAPublicKeyJWK  $pub_key  RSA public key
58
+	 * @param RSAPrivateKeyJWK $priv_key Optional RSA private key
59
+	 */
60
+	protected function __construct(RSAPublicKeyJWK $pub_key,
61
+		?RSAPrivateKeyJWK $priv_key = null)
62
+	{
63
+		$this->_publicKey = $pub_key;
64
+		$this->_privateKey = $priv_key;
65
+	}
66
+
67
+	/**
68
+	 * Initialize from JWK.
69
+	 *
70
+	 * @param JWK    $jwk
71
+	 * @param Header $header
72
+	 *
73
+	 * @throws \UnexpectedValueException
74
+	 *
75
+	 * @return self
76
+	 */
77
+	public static function fromJWK(JWK $jwk, Header $header): KeyManagementAlgorithm
78
+	{
79
+		$alg = JWA::deriveAlgorithmName($header, $jwk);
80
+		if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) {
81
+			throw new \UnexpectedValueException("Unsupported algorithm '{$alg}'.");
82
+		}
83
+		$cls = self::MAP_ALGO_TO_CLASS[$alg];
84
+		if ($jwk->has(...RSAPrivateKeyJWK::MANAGED_PARAMS)) {
85
+			return $cls::fromPrivateKey(RSAPrivateKeyJWK::fromJWK($jwk));
86
+		}
87
+		return $cls::fromPublicKey(RSAPublicKeyJWK::fromJWK($jwk));
88
+	}
89
+
90
+	/**
91
+	 * Initialize from a public key.
92
+	 *
93
+	 * @param RSAPublicKeyJWK $jwk
94
+	 *
95
+	 * @return self
96
+	 */
97
+	public static function fromPublicKey(RSAPublicKeyJWK $jwk): self
98
+	{
99
+		return new static($jwk);
100
+	}
101
+
102
+	/**
103
+	 * Initialize from a private key.
104
+	 *
105
+	 * @param RSAPrivateKeyJWK $jwk
106
+	 *
107
+	 * @return self
108
+	 */
109
+	public static function fromPrivateKey(RSAPrivateKeyJWK $jwk): self
110
+	{
111
+		return new static($jwk->publicKey(), $jwk);
112
+	}
113
+
114
+	/**
115
+	 * Get the public key.
116
+	 *
117
+	 * @return RSAPublicKeyJWK
118
+	 */
119
+	public function publicKey(): RSAPublicKeyJWK
120
+	{
121
+		return $this->_publicKey;
122
+	}
123
+
124
+	/**
125
+	 * Check whether the private key is present.
126
+	 *
127
+	 * @return bool
128
+	 */
129
+	public function hasPrivateKey(): bool
130
+	{
131
+		return isset($this->_privateKey);
132
+	}
133
+
134
+	/**
135
+	 * Get the private key.
136
+	 *
137
+	 * @throws \LogicException
138
+	 *
139
+	 * @return RSAPrivateKeyJWK
140
+	 */
141
+	public function privateKey(): RSAPrivateKeyJWK
142
+	{
143
+		if (!$this->hasPrivateKey()) {
144
+			throw new \LogicException('Private key not set.');
145
+		}
146
+		return $this->_privateKey;
147
+	}
148
+
149
+	/**
150
+	 * {@inheritdoc}
151
+	 */
152
+	public function headerParameters(): array
153
+	{
154
+		return array_merge(parent::headerParameters(),
155
+			[AlgorithmParameter::fromAlgorithm($this)]);
156
+	}
157
+
158
+	/**
159
+	 * Get the padding scheme.
160
+	 *
161
+	 * @return int
162
+	 */
163
+	abstract protected function _paddingScheme(): int;
164
+
165
+	/**
166
+	 * {@inheritdoc}
167
+	 */
168
+	protected function _encryptKey(string $key, Header &$header): string
169
+	{
170
+		$pubkey = openssl_pkey_get_public(
171
+			$this->publicKey()->toPEM()->string());
172
+		if (false === $pubkey) {
173
+			throw new \RuntimeException(
174
+				'openssl_pkey_get_public() failed: ' .
175
+					 $this->_getLastOpenSSLError());
176
+		}
177
+		$result = openssl_public_encrypt($key, $crypted, $pubkey,
178
+			$this->_paddingScheme());
179
+		if (!$result) {
180
+			throw new \RuntimeException(
181
+				'openssl_public_encrypt() failed: ' .
182
+					 $this->_getLastOpenSSLError());
183
+		}
184
+		return $crypted;
185
+	}
186
+
187
+	/**
188
+	 * {@inheritdoc}
189
+	 */
190
+	protected function _decryptKey(string $ciphertext, Header $header): string
191
+	{
192
+		$privkey = openssl_pkey_get_private(
193
+			$this->privateKey()->toPEM()->string());
194
+		if (false === $privkey) {
195
+			throw new \RuntimeException(
196
+				'openssl_pkey_get_private() failed: ' .
197
+					 $this->_getLastOpenSSLError());
198
+		}
199
+		$result = openssl_private_decrypt($ciphertext, $cek, $privkey,
200
+			$this->_paddingScheme());
201
+		if (!$result) {
202
+			throw new \RuntimeException(
203
+				'openssl_private_decrypt() failed: ' .
204
+					 $this->_getLastOpenSSLError());
205
+		}
206
+		return $cek;
207
+	}
208
+
209
+	/**
210
+	 * Get last OpenSSL error message.
211
+	 *
212
+	 * @return null|string
213
+	 */
214
+	protected function _getLastOpenSSLError(): ?string
215
+	{
216
+		$msg = null;
217
+		while (false !== ($err = openssl_error_string())) {
218
+			$msg = $err;
219
+		}
220
+		return $msg;
221
+	}
222 222
 }
Please login to merge, or discard this patch.