Passed
Push — master ( d1c5df...3124aa )
by Smoren
02:11
created
src/Helpers/AsymmetricEncryptionHelper.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     public static function generateKeyPair(): array
20 20
     {
21 21
         $keyPair = openssl_pkey_new();
22
-        if(!$keyPair) {
22
+        if (!$keyPair) {
23 23
             throw new AsymmetricEncryptionException(
24 24
                 'openssl_pkey_new() returned false',
25 25
                 AsymmetricEncryptionException::OPENSSL_ERROR
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 
29 29
         openssl_pkey_export($keyPair, $privateKey);
30 30
         $details = openssl_pkey_get_details($keyPair);
31
-        if(!$details) {
31
+        if (!$details) {
32 32
             throw new AsymmetricEncryptionException(
33 33
                 'openssl_pkey_get_details() returned false',
34 34
                 AsymmetricEncryptionException::OPENSSL_ERROR
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     public static function encryptByPublicKey($data, string $publicKey): string
52 52
     {
53 53
         static::validatePublicKey($publicKey);
54
-        if(!openssl_public_encrypt(JsonHelper::encode($data), $dataEncrypted, $publicKey)) {
54
+        if (!openssl_public_encrypt(JsonHelper::encode($data), $dataEncrypted, $publicKey)) {
55 55
             throw new AsymmetricEncryptionException(
56 56
                 'openssl_public_encrypt() returned false',
57 57
                 AsymmetricEncryptionException::CANNOT_ENCRYPT
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     public static function encryptByPrivateKey($data, string $privateKey): string
72 72
     {
73 73
         static::validatePrivateKey($privateKey);
74
-        if(!openssl_private_encrypt(JsonHelper::encode($data), $dataEncrypted, $privateKey)) {
74
+        if (!openssl_private_encrypt(JsonHelper::encode($data), $dataEncrypted, $privateKey)) {
75 75
             throw new AsymmetricEncryptionException(
76 76
                 'openssl_private_encrypt() returned false',
77 77
                 AsymmetricEncryptionException::CANNOT_ENCRYPT
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         static::validatePublicKey($publicKey);
93 93
         openssl_public_decrypt(base64_decode($dataEncrypted), $dataDecrypted, $publicKey);
94 94
 
95
-        if($dataDecrypted === null) {
95
+        if ($dataDecrypted === null) {
96 96
             throw new AsymmetricEncryptionException(
97 97
                 'cannot decrypt by public key',
98 98
                 AsymmetricEncryptionException::CANNOT_DECRYPT
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         static::validatePrivateKey($privateKey);
115 115
         openssl_private_decrypt(base64_decode($dataEncrypted), $dataDecrypted, $privateKey);
116 116
 
117
-        if($dataDecrypted === null) {
117
+        if ($dataDecrypted === null) {
118 118
             throw new AsymmetricEncryptionException(
119 119
                 'cannot decrypt by private key',
120 120
                 AsymmetricEncryptionException::CANNOT_DECRYPT
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         int $algorithm = OPENSSL_ALGO_SHA256
157 157
     ): void {
158 158
         static::validatePublicKey($publicKey);
159
-        if(!openssl_verify(JsonHelper::encode($data), $signature, $publicKey, $algorithm)) {
159
+        if (!openssl_verify(JsonHelper::encode($data), $signature, $publicKey, $algorithm)) {
160 160
             throw new AsymmetricEncryptionException('wrong signature', AsymmetricEncryptionException::CANNOT_VERIFY);
161 161
         }
162 162
     }
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
         $isCorrect = true;
199 199
 
200
-        if(
200
+        if (
201 201
             $endLineBreak !== "" ||
202 202
             $beginString !== "-----BEGIN {$keyType} KEY-----" ||
203 203
             $endString !== "-----END {$keyType} KEY-----" ||
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
         ) {
206 206
             $isCorrect = false;
207 207
         } else {
208
-            foreach($arPublicKey as $part) {
209
-                if(!preg_match('/^.{64}$/', $part)) {
208
+            foreach ($arPublicKey as $part) {
209
+                if (!preg_match('/^.{64}$/', $part)) {
210 210
                     $isCorrect = false;
211 211
                     break;
212 212
                 }
213 213
             }
214 214
         }
215 215
 
216
-        if(!$isCorrect) {
216
+        if (!$isCorrect) {
217 217
             throw new AsymmetricEncryptionException(
218 218
                 'invalid key format',
219 219
                 AsymmetricEncryptionException::INVALID_KEY_FORMAT
Please login to merge, or discard this patch.