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 ( 59f4b4...e271c1 )
by Joni
03:51
created
lib/JWX/Parameter/Feature/Base64UIntValue.php 1 patch
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.
lib/JWX/JWT/Claim/Feature/NumericDateClaim.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -9,99 +9,99 @@
 block discarded – undo
9 9
  */
10 10
 trait NumericDateClaim
11 11
 {
12
-    /**
13
-     * Constructor.
14
-     *
15
-     * @param int $timestamp Unix timestamp
16
-     */
17
-    abstract public function __construct(int $timestamp);
12
+	/**
13
+	 * Constructor.
14
+	 *
15
+	 * @param int $timestamp Unix timestamp
16
+	 */
17
+	abstract public function __construct(int $timestamp);
18 18
 
19
-    /**
20
-     * Get the parameter value.
21
-     *
22
-     * @return string
23
-     */
24
-    abstract public function value();
19
+	/**
20
+	 * Get the parameter value.
21
+	 *
22
+	 * @return string
23
+	 */
24
+	abstract public function value();
25 25
 
26
-    /**
27
-     * Initialize instance from date/time string.
28
-     *
29
-     * @param string $time `strtotime` compatible time string
30
-     * @param string $tz   Default timezone
31
-     *
32
-     * @throws \RuntimeException
33
-     *
34
-     * @return static
35
-     */
36
-    public static function fromString(string $time, string $tz = 'UTC')
37
-    {
38
-        try {
39
-            $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz));
40
-            return new static($dt->getTimestamp());
41
-        } catch (\Exception $e) {
42
-            throw new \RuntimeException(
43
-                'Failed to create DateTime: ' .
44
-                     self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
45
-        }
46
-    }
26
+	/**
27
+	 * Initialize instance from date/time string.
28
+	 *
29
+	 * @param string $time `strtotime` compatible time string
30
+	 * @param string $tz   Default timezone
31
+	 *
32
+	 * @throws \RuntimeException
33
+	 *
34
+	 * @return static
35
+	 */
36
+	public static function fromString(string $time, string $tz = 'UTC')
37
+	{
38
+		try {
39
+			$dt = new \DateTimeImmutable($time, self::_createTimeZone($tz));
40
+			return new static($dt->getTimestamp());
41
+		} catch (\Exception $e) {
42
+			throw new \RuntimeException(
43
+				'Failed to create DateTime: ' .
44
+					 self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
45
+		}
46
+	}
47 47
 
48
-    /**
49
-     * Get date as a unix timestamp.
50
-     *
51
-     * @return int
52
-     */
53
-    public function timestamp(): int
54
-    {
55
-        return (int) $this->value();
56
-    }
48
+	/**
49
+	 * Get date as a unix timestamp.
50
+	 *
51
+	 * @return int
52
+	 */
53
+	public function timestamp(): int
54
+	{
55
+		return (int) $this->value();
56
+	}
57 57
 
58
-    /**
59
-     * Get date as a datetime object.
60
-     *
61
-     * @param string $tz Timezone
62
-     *
63
-     * @throws \RuntimeException
64
-     *
65
-     * @return \DateTimeImmutable
66
-     */
67
-    public function dateTime(string $tz = 'UTC'): \DateTimeImmutable
68
-    {
69
-        $dt = \DateTimeImmutable::createFromFormat('!U', strval($this->value()),
70
-            self::_createTimeZone($tz));
71
-        if (false === $dt) {
72
-            throw new \RuntimeException(
73
-                'Failed to create DateTime: ' .
74
-                     self::_getLastDateTimeImmutableErrorsStr());
75
-        }
76
-        return $dt;
77
-    }
58
+	/**
59
+	 * Get date as a datetime object.
60
+	 *
61
+	 * @param string $tz Timezone
62
+	 *
63
+	 * @throws \RuntimeException
64
+	 *
65
+	 * @return \DateTimeImmutable
66
+	 */
67
+	public function dateTime(string $tz = 'UTC'): \DateTimeImmutable
68
+	{
69
+		$dt = \DateTimeImmutable::createFromFormat('!U', strval($this->value()),
70
+			self::_createTimeZone($tz));
71
+		if (false === $dt) {
72
+			throw new \RuntimeException(
73
+				'Failed to create DateTime: ' .
74
+					 self::_getLastDateTimeImmutableErrorsStr());
75
+		}
76
+		return $dt;
77
+	}
78 78
 
79
-    /**
80
-     * Create DateTimeZone object from string.
81
-     *
82
-     * @param string $tz
83
-     *
84
-     * @throws \UnexpectedValueException
85
-     *
86
-     * @return \DateTimeZone
87
-     */
88
-    private static function _createTimeZone(string $tz): \DateTimeZone
89
-    {
90
-        try {
91
-            return new \DateTimeZone($tz);
92
-        } catch (\Exception $e) {
93
-            throw new \UnexpectedValueException('Invalid timezone.', 0, $e);
94
-        }
95
-    }
79
+	/**
80
+	 * Create DateTimeZone object from string.
81
+	 *
82
+	 * @param string $tz
83
+	 *
84
+	 * @throws \UnexpectedValueException
85
+	 *
86
+	 * @return \DateTimeZone
87
+	 */
88
+	private static function _createTimeZone(string $tz): \DateTimeZone
89
+	{
90
+		try {
91
+			return new \DateTimeZone($tz);
92
+		} catch (\Exception $e) {
93
+			throw new \UnexpectedValueException('Invalid timezone.', 0, $e);
94
+		}
95
+	}
96 96
 
97
-    /**
98
-     * Get last error caused by DateTimeImmutable.
99
-     *
100
-     * @return string
101
-     */
102
-    private static function _getLastDateTimeImmutableErrorsStr(): string
103
-    {
104
-        $errors = \DateTimeImmutable::getLastErrors()['errors'];
105
-        return implode(', ', $errors);
106
-    }
97
+	/**
98
+	 * Get last error caused by DateTimeImmutable.
99
+	 *
100
+	 * @return string
101
+	 */
102
+	private static function _getLastDateTimeImmutableErrorsStr(): string
103
+	{
104
+		$errors = \DateTimeImmutable::getLastErrors()['errors'];
105
+		return implode(', ', $errors);
106
+	}
107 107
 }
Please login to merge, or discard this patch.
lib/JWX/JWE/KeyAlgorithm/RSAESKeyAlgorithm.php 1 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.
lib/JWX/JWE/EncryptionAlgorithm/A128GCMAlgorithm.php 1 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 A128GCMAlgorithm extends AESGCMAlgorithm
15 15
 {
16
-    /**
17
-     * {@inheritdoc}
18
-     */
19
-    public function encryptionAlgorithmParamValue(): string
20
-    {
21
-        return JWA::ALGO_A128GCM;
22
-    }
16
+	/**
17
+	 * {@inheritdoc}
18
+	 */
19
+	public function encryptionAlgorithmParamValue(): string
20
+	{
21
+		return JWA::ALGO_A128GCM;
22
+	}
23 23
 
24
-    /**
25
-     * {@inheritdoc}
26
-     */
27
-    public function keySize(): int
28
-    {
29
-        return 16;
30
-    }
24
+	/**
25
+	 * {@inheritdoc}
26
+	 */
27
+	public function keySize(): int
28
+	{
29
+		return 16;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
lib/JWX/JWE/EncryptionAlgorithm/A192GCMAlgorithm.php 1 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/A256GCMAlgorithm.php 1 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/AESGCMAlgorithm.php 1 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/A192GCMKWAlgorithm.php 1 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 A192GCMKWAlgorithm extends AESGCMKWAlgorithm
15 15
 {
16
-    /**
17
-     * {@inheritdoc}
18
-     */
19
-    public function algorithmParamValue(): string
20
-    {
21
-        return JWA::ALGO_A192GCMKW;
22
-    }
16
+	/**
17
+	 * {@inheritdoc}
18
+	 */
19
+	public function algorithmParamValue(): string
20
+	{
21
+		return JWA::ALGO_A192GCMKW;
22
+	}
23 23
 
24
-    /**
25
-     * {@inheritdoc}
26
-     */
27
-    protected function _keySize(): int
28
-    {
29
-        return 24;
30
-    }
24
+	/**
25
+	 * {@inheritdoc}
26
+	 */
27
+	protected function _keySize(): int
28
+	{
29
+		return 24;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
lib/JWX/JWE/KeyAlgorithm/AESGCMKWAlgorithm.php 1 patch
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -22,147 +22,147 @@
 block discarded – undo
22 22
  */
23 23
 abstract class AESGCMKWAlgorithm extends KeyManagementAlgorithm
24 24
 {
25
-    use RandomCEK;
26
-
27
-    /**
28
-     * Mapping from algorithm name to class name.
29
-     *
30
-     * @internal
31
-     *
32
-     * @var array
33
-     */
34
-    const MAP_ALGO_TO_CLASS = [
35
-        JWA::ALGO_A128GCMKW => A128GCMKWAlgorithm::class,
36
-        JWA::ALGO_A192GCMKW => A192GCMKWAlgorithm::class,
37
-        JWA::ALGO_A256GCMKW => A256GCMKWAlgorithm::class,
38
-    ];
39
-
40
-    /**
41
-     * Required IV size in bytes.
42
-     *
43
-     * @var int
44
-     */
45
-    const IV_SIZE = 12;
46
-
47
-    /**
48
-     * Authentication tag size in bytes.
49
-     *
50
-     * @var int
51
-     */
52
-    const AUTH_TAG_SIZE = 16;
53
-
54
-    /**
55
-     * Key encryption key.
56
-     *
57
-     * @var string
58
-     */
59
-    protected $_kek;
60
-
61
-    /**
62
-     * Initialization vector.
63
-     *
64
-     * @var string
65
-     */
66
-    protected $_iv;
67
-
68
-    /**
69
-     * Constructor.
70
-     *
71
-     * @param string $kek Key encryption key
72
-     * @param string $iv  Initialization vector
73
-     */
74
-    public function __construct(string $kek, string $iv)
75
-    {
76
-        if (strlen($kek) !== $this->_keySize()) {
77
-            throw new \LengthException('Invalid key size.');
78
-        }
79
-        if (self::IV_SIZE !== strlen($iv)) {
80
-            throw new \LengthException('Initialization vector must be 96 bits.');
81
-        }
82
-        $this->_kek = $kek;
83
-        $this->_iv = $iv;
84
-    }
85
-
86
-    /**
87
-     * Initialize from JWK.
88
-     *
89
-     * @param JWK    $jwk
90
-     * @param Header $header
91
-     *
92
-     * @throws \UnexpectedValueException
93
-     *
94
-     * @return self
95
-     */
96
-    public static function fromJWK(JWK $jwk, Header $header): KeyManagementAlgorithm
97
-    {
98
-        $jwk = SymmetricKeyJWK::fromJWK($jwk);
99
-        if (!$header->hasInitializationVector()) {
100
-            throw new \UnexpectedValueException('No initialization vector.');
101
-        }
102
-        $iv = $header->initializationVector()->initializationVector();
103
-        $alg = JWA::deriveAlgorithmName($header, $jwk);
104
-        if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) {
105
-            throw new \UnexpectedValueException("Unsupported algorithm '{$alg}'.");
106
-        }
107
-        $cls = self::MAP_ALGO_TO_CLASS[$alg];
108
-        return new $cls($jwk->key(), $iv);
109
-    }
110
-
111
-    /**
112
-     * Initialize from key encryption key with random IV.
113
-     *
114
-     * Key size must match the underlying cipher.
115
-     *
116
-     * @param string $key Key encryption key
117
-     *
118
-     * @return self
119
-     */
120
-    public static function fromKey(string $key): self
121
-    {
122
-        $iv = openssl_random_pseudo_bytes(self::IV_SIZE);
123
-        return new static($key, $iv);
124
-    }
125
-
126
-    /**
127
-     * {@inheritdoc}
128
-     */
129
-    public function headerParameters(): array
130
-    {
131
-        return array_merge(parent::headerParameters(),
132
-            [AlgorithmParameter::fromAlgorithm($this),
133
-                InitializationVectorParameter::fromString($this->_iv), ]);
134
-    }
135
-
136
-    /**
137
-     * Get the required key size.
138
-     *
139
-     * @return int
140
-     */
141
-    abstract protected function _keySize(): int;
142
-
143
-    /**
144
-     * {@inheritdoc}
145
-     */
146
-    protected function _encryptKey(string $key, Header &$header): string
147
-    {
148
-        [$ciphertext, $auth_tag] = AESGCM::encrypt($key, '', $this->_kek,
149
-            $this->_iv, self::AUTH_TAG_SIZE);
150
-        // insert authentication tag to the header
151
-        $header = $header->withParameters(
152
-            AuthenticationTagParameter::fromString($auth_tag));
153
-        return $ciphertext;
154
-    }
155
-
156
-    /**
157
-     * {@inheritdoc}
158
-     */
159
-    protected function _decryptKey(string $ciphertext, Header $header): string
160
-    {
161
-        if (!$header->hasAuthenticationTag()) {
162
-            throw new \RuntimeException(
163
-                "Header doesn't contain authentication tag.");
164
-        }
165
-        $auth_tag = $header->authenticationTag()->authenticationTag();
166
-        return AESGCM::decrypt($ciphertext, $auth_tag, '', $this->_kek, $this->_iv);
167
-    }
25
+	use RandomCEK;
26
+
27
+	/**
28
+	 * Mapping from algorithm name to class name.
29
+	 *
30
+	 * @internal
31
+	 *
32
+	 * @var array
33
+	 */
34
+	const MAP_ALGO_TO_CLASS = [
35
+		JWA::ALGO_A128GCMKW => A128GCMKWAlgorithm::class,
36
+		JWA::ALGO_A192GCMKW => A192GCMKWAlgorithm::class,
37
+		JWA::ALGO_A256GCMKW => A256GCMKWAlgorithm::class,
38
+	];
39
+
40
+	/**
41
+	 * Required IV size in bytes.
42
+	 *
43
+	 * @var int
44
+	 */
45
+	const IV_SIZE = 12;
46
+
47
+	/**
48
+	 * Authentication tag size in bytes.
49
+	 *
50
+	 * @var int
51
+	 */
52
+	const AUTH_TAG_SIZE = 16;
53
+
54
+	/**
55
+	 * Key encryption key.
56
+	 *
57
+	 * @var string
58
+	 */
59
+	protected $_kek;
60
+
61
+	/**
62
+	 * Initialization vector.
63
+	 *
64
+	 * @var string
65
+	 */
66
+	protected $_iv;
67
+
68
+	/**
69
+	 * Constructor.
70
+	 *
71
+	 * @param string $kek Key encryption key
72
+	 * @param string $iv  Initialization vector
73
+	 */
74
+	public function __construct(string $kek, string $iv)
75
+	{
76
+		if (strlen($kek) !== $this->_keySize()) {
77
+			throw new \LengthException('Invalid key size.');
78
+		}
79
+		if (self::IV_SIZE !== strlen($iv)) {
80
+			throw new \LengthException('Initialization vector must be 96 bits.');
81
+		}
82
+		$this->_kek = $kek;
83
+		$this->_iv = $iv;
84
+	}
85
+
86
+	/**
87
+	 * Initialize from JWK.
88
+	 *
89
+	 * @param JWK    $jwk
90
+	 * @param Header $header
91
+	 *
92
+	 * @throws \UnexpectedValueException
93
+	 *
94
+	 * @return self
95
+	 */
96
+	public static function fromJWK(JWK $jwk, Header $header): KeyManagementAlgorithm
97
+	{
98
+		$jwk = SymmetricKeyJWK::fromJWK($jwk);
99
+		if (!$header->hasInitializationVector()) {
100
+			throw new \UnexpectedValueException('No initialization vector.');
101
+		}
102
+		$iv = $header->initializationVector()->initializationVector();
103
+		$alg = JWA::deriveAlgorithmName($header, $jwk);
104
+		if (!array_key_exists($alg, self::MAP_ALGO_TO_CLASS)) {
105
+			throw new \UnexpectedValueException("Unsupported algorithm '{$alg}'.");
106
+		}
107
+		$cls = self::MAP_ALGO_TO_CLASS[$alg];
108
+		return new $cls($jwk->key(), $iv);
109
+	}
110
+
111
+	/**
112
+	 * Initialize from key encryption key with random IV.
113
+	 *
114
+	 * Key size must match the underlying cipher.
115
+	 *
116
+	 * @param string $key Key encryption key
117
+	 *
118
+	 * @return self
119
+	 */
120
+	public static function fromKey(string $key): self
121
+	{
122
+		$iv = openssl_random_pseudo_bytes(self::IV_SIZE);
123
+		return new static($key, $iv);
124
+	}
125
+
126
+	/**
127
+	 * {@inheritdoc}
128
+	 */
129
+	public function headerParameters(): array
130
+	{
131
+		return array_merge(parent::headerParameters(),
132
+			[AlgorithmParameter::fromAlgorithm($this),
133
+				InitializationVectorParameter::fromString($this->_iv), ]);
134
+	}
135
+
136
+	/**
137
+	 * Get the required key size.
138
+	 *
139
+	 * @return int
140
+	 */
141
+	abstract protected function _keySize(): int;
142
+
143
+	/**
144
+	 * {@inheritdoc}
145
+	 */
146
+	protected function _encryptKey(string $key, Header &$header): string
147
+	{
148
+		[$ciphertext, $auth_tag] = AESGCM::encrypt($key, '', $this->_kek,
149
+			$this->_iv, self::AUTH_TAG_SIZE);
150
+		// insert authentication tag to the header
151
+		$header = $header->withParameters(
152
+			AuthenticationTagParameter::fromString($auth_tag));
153
+		return $ciphertext;
154
+	}
155
+
156
+	/**
157
+	 * {@inheritdoc}
158
+	 */
159
+	protected function _decryptKey(string $ciphertext, Header $header): string
160
+	{
161
+		if (!$header->hasAuthenticationTag()) {
162
+			throw new \RuntimeException(
163
+				"Header doesn't contain authentication tag.");
164
+		}
165
+		$auth_tag = $header->authenticationTag()->authenticationTag();
166
+		return AESGCM::decrypt($ciphertext, $auth_tag, '', $this->_kek, $this->_iv);
167
+	}
168 168
 }
Please login to merge, or discard this patch.