@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | public static function encode($value): string |
16 | 16 | { |
17 | 17 | $result = json_encode($value); |
18 | - if($error = json_last_error()) { |
|
18 | + if ($error = json_last_error()) { |
|
19 | 19 | throw new JsonException(json_last_error_msg(), $error); |
20 | 20 | } |
21 | 21 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public static function decode(string $json) |
33 | 33 | { |
34 | 34 | $result = json_decode($json, true); |
35 | - if($error = json_last_error()) { |
|
35 | + if ($error = json_last_error()) { |
|
36 | 36 | throw new JsonException(json_last_error_msg(), $error); |
37 | 37 | } |
38 | 38 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | public static function generateKeyPair(): array |
15 | 15 | { |
16 | 16 | $keyPair = openssl_pkey_new(); |
17 | - if(!$keyPair) { |
|
17 | + if (!$keyPair) { |
|
18 | 18 | throw new AsymmetricEncryptionException( |
19 | 19 | 'openssl_pkey_new() returned false', |
20 | 20 | AsymmetricEncryptionException::OPENSSL_ERROR |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | openssl_pkey_export($keyPair, $privateKey); |
25 | 25 | $details = openssl_pkey_get_details($keyPair); |
26 | - if(!$details) { |
|
26 | + if (!$details) { |
|
27 | 27 | throw new AsymmetricEncryptionException( |
28 | 28 | 'openssl_pkey_get_details() returned false', |
29 | 29 | AsymmetricEncryptionException::OPENSSL_ERROR |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | static::validatePublicKey($publicKey); |
75 | 75 | openssl_public_decrypt(base64_decode($dataEncrypted), $dataDecrypted, $publicKey); |
76 | 76 | |
77 | - if($dataDecrypted === null) { |
|
77 | + if ($dataDecrypted === null) { |
|
78 | 78 | throw new AsymmetricEncryptionException( |
79 | 79 | 'cannot decrypt by public key', |
80 | 80 | AsymmetricEncryptionException::CANNOT_DECRYPT |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | static::validatePrivateKey($privateKey); |
96 | 96 | openssl_private_decrypt(base64_decode($dataEncrypted), $dataDecrypted, $privateKey); |
97 | 97 | |
98 | - if($dataDecrypted === null) { |
|
98 | + if ($dataDecrypted === null) { |
|
99 | 99 | throw new AsymmetricEncryptionException( |
100 | 100 | 'cannot decrypt by private key', |
101 | 101 | AsymmetricEncryptionException::CANNOT_DECRYPT |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | int $algorithm = OPENSSL_ALGO_SHA256 |
136 | 136 | ): void { |
137 | 137 | static::validatePublicKey($publicKey); |
138 | - if(!openssl_verify(JsonHelper::encode($data), $signature, $publicKey, $algorithm)) { |
|
138 | + if (!openssl_verify(JsonHelper::encode($data), $signature, $publicKey, $algorithm)) { |
|
139 | 139 | throw new AsymmetricEncryptionException('wrong signature', AsymmetricEncryptionException::CANNOT_VERIFY); |
140 | 140 | } |
141 | 141 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | $isCorrect = true; |
175 | 175 | |
176 | - if( |
|
176 | + if ( |
|
177 | 177 | $endLineBreak !== "" || |
178 | 178 | $beginString !== "-----BEGIN {$keyType} KEY-----" || |
179 | 179 | $endString !== "-----END {$keyType} KEY-----" || |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | ) { |
182 | 182 | $isCorrect = false; |
183 | 183 | } else { |
184 | - foreach($arPublicKey as $part) { |
|
185 | - if(!preg_match('/^.{64}$/', $part)) { |
|
184 | + foreach ($arPublicKey as $part) { |
|
185 | + if (!preg_match('/^.{64}$/', $part)) { |
|
186 | 186 | $isCorrect = false; |
187 | 187 | break; |
188 | 188 | } |
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
192 | - if(!$isCorrect) { |
|
192 | + if (!$isCorrect) { |
|
193 | 193 | throw new AsymmetricEncryptionException( |
194 | 194 | 'invalid key format', |
195 | 195 | AsymmetricEncryptionException::INVALID_KEY_FORMAT |
@@ -21,21 +21,21 @@ discard block |
||
21 | 21 | $data = JsonHelper::encode($data); |
22 | 22 | |
23 | 23 | $ivLen = openssl_cipher_iv_length($cipherMethod); |
24 | - if($ivLen === false) { |
|
24 | + if ($ivLen === false) { |
|
25 | 25 | throw new SymmetricEncryptionException( |
26 | 26 | 'openssl_cipher_iv_length() returned false', |
27 | 27 | SymmetricEncryptionException::OPENSSL_ERROR |
28 | 28 | ); |
29 | 29 | } |
30 | 30 | $iv = openssl_random_pseudo_bytes($ivLen); |
31 | - if(!$iv) { |
|
31 | + if (!$iv) { |
|
32 | 32 | throw new SymmetricEncryptionException( |
33 | 33 | 'openssl_random_pseudo_bytes() returned false', |
34 | 34 | SymmetricEncryptionException::OPENSSL_ERROR |
35 | 35 | ); |
36 | 36 | } |
37 | 37 | $cipherText = openssl_encrypt($data, $cipherMethod, $secretKey, OPENSSL_RAW_DATA, $iv); |
38 | - if($cipherText === false) { |
|
38 | + if ($cipherText === false) { |
|
39 | 39 | throw new SymmetricEncryptionException( |
40 | 40 | 'openssl_encrypt() returned false', |
41 | 41 | SymmetricEncryptionException::OPENSSL_ERROR |
@@ -59,19 +59,19 @@ discard block |
||
59 | 59 | |
60 | 60 | $c = base64_decode($encryptedData); |
61 | 61 | $ivLen = openssl_cipher_iv_length($cipherMethod); |
62 | - if($ivLen === false) { |
|
62 | + if ($ivLen === false) { |
|
63 | 63 | throw new SymmetricEncryptionException( |
64 | 64 | 'openssl_cipher_iv_length() returned false', |
65 | 65 | SymmetricEncryptionException::OPENSSL_ERROR |
66 | 66 | ); |
67 | 67 | } |
68 | 68 | $iv = substr($c, 0, $ivLen); |
69 | - $hmac = substr($c, $ivLen, $sha2len=32); |
|
69 | + $hmac = substr($c, $ivLen, $sha2len = 32); |
|
70 | 70 | $cipherText = substr($c, $ivLen+$sha2len); |
71 | 71 | |
72 | 72 | $data = openssl_decrypt($cipherText, $cipherMethod, $secretKey, OPENSSL_RAW_DATA, $iv); |
73 | 73 | |
74 | - if($data === false) { |
|
74 | + if ($data === false) { |
|
75 | 75 | throw new SymmetricEncryptionException( |
76 | 76 | 'incorrect secret key', |
77 | 77 | SymmetricEncryptionException::CANNOT_DECRYPT |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public static function checkCipherMethodAvailable(string $cipherMethod): void |
96 | 96 | { |
97 | - if(!in_array($cipherMethod, static::getCipherMethodList(), true)) { |
|
97 | + if (!in_array($cipherMethod, static::getCipherMethodList(), true)) { |
|
98 | 98 | throw new SymmetricEncryptionException( |
99 | 99 | "unknown cipher method '{$cipherMethod}'", |
100 | 100 | SymmetricEncryptionException::UNKNOWN_METHOD |