Skip to content

Commit e0eef8d

Browse files
committed
formatting
1 parent 3800323 commit e0eef8d

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/Illuminate/Encryption/Encrypter.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@
1010

1111
class Encrypter implements EncrypterContract, StringEncrypter
1212
{
13-
/**
14-
* The supported cipher algorithms and their properties.
15-
*
16-
* @var array
17-
*/
18-
private static $supportedCiphers = [
19-
'AES-128-CBC' => ['size' => 16, 'aead' => false],
20-
'AES-256-CBC' => ['size' => 32, 'aead' => false],
21-
'AES-128-GCM' => ['size' => 16, 'aead' => true],
22-
'AES-256-GCM' => ['size' => 32, 'aead' => true],
23-
];
24-
2513
/**
2614
* The encryption key.
2715
*
@@ -36,6 +24,18 @@ class Encrypter implements EncrypterContract, StringEncrypter
3624
*/
3725
protected $cipher;
3826

27+
/**
28+
* The supported cipher algorithms and their properties.
29+
*
30+
* @var array
31+
*/
32+
private static $supportedCiphers = [
33+
'AES-128-CBC' => ['size' => 16, 'aead' => false],
34+
'AES-256-CBC' => ['size' => 32, 'aead' => false],
35+
'AES-128-GCM' => ['size' => 16, 'aead' => true],
36+
'AES-256-GCM' => ['size' => 32, 'aead' => true],
37+
];
38+
3939
/**
4040
* Create a new encrypter instance.
4141
*
@@ -51,7 +51,8 @@ public function __construct($key, $cipher = 'AES-128-CBC')
5151

5252
if (! static::supported($key, $cipher)) {
5353
$ciphers = implode(', ', array_keys(self::$supportedCiphers));
54-
throw new RuntimeException("Unsupported cipher or incorrect key length. Supported ciphers are: $ciphers.");
54+
55+
throw new RuntimeException("Unsupported cipher or incorrect key length. Supported ciphers are: {$ciphers}.");
5556
}
5657

5758
$this->key = $key;
@@ -98,9 +99,8 @@ public function encrypt($value, $serialize = true)
9899
{
99100
$iv = random_bytes(openssl_cipher_iv_length($this->cipher));
100101

101-
// A tag (mac) is returned by openssl_encrypt for AEAD ciphers.
102-
// Including $tag in the call for non-AEAD ciphers results in a warning before PHP 8.1.
103102
$tag = '';
103+
104104
$value = self::$supportedCiphers[$this->cipher]['aead']
105105
? \openssl_encrypt(
106106
$serialize ? serialize($value) : $value,
@@ -119,10 +119,9 @@ public function encrypt($value, $serialize = true)
119119
$tag = base64_encode($tag);
120120

121121
$mac = self::$supportedCiphers[$this->cipher]['aead']
122-
? '' // For AEAD-algoritms, the tag/mac is returned by openssl_encrypt
122+
? '' // For AEAD-algoritms, the tag / MAC is returned by openssl_encrypt...
123123
: $this->hash($iv, $value);
124124

125-
// Both tag and mac are included for compatibility reasons. A breaking update could use the same name for these.
126125
$json = json_encode(compact('iv', 'value', 'mac', 'tag'), JSON_UNESCAPED_SLASHES);
127126

128127
if (json_last_error() !== JSON_ERROR_NONE) {
@@ -220,7 +219,6 @@ protected function getJsonPayload($payload)
220219
throw new DecryptException('The payload is invalid.');
221220
}
222221

223-
// We only need to check for the valid MAC if a non-AEAD algorithm is used
224222
if (! self::$supportedCiphers[$this->cipher]['aead'] && ! $this->validMac($payload)) {
225223
throw new DecryptException('The MAC is invalid.');
226224
}

0 commit comments

Comments
 (0)