Passed
Push — master ( db78bc...ade9aa )
by Smoren
12:04 queued 09:55
created
src/Helpers/JsonHelper.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Helpers/SymmetricEncryptionHelper.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,21 +21,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
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.
src/Helpers/AsymmetricLargeDataEncryptionHelper.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
         $internalKeyEncrypted = AsymmetricEncryptionHelper::encryptByPublicKey($internalKey, $publicKey);
37 37
         try {
38 38
             $dataEncrypted = SymmetricEncryptionHelper::encrypt($data, $internalKey);
39
-        } catch(SymmetricEncryptionException $e) {
39
+        } catch (SymmetricEncryptionException $e) {
40 40
             throw new AsymmetricEncryptionException(
41 41
                 'cannot encrypt',
42 42
                 AsymmetricEncryptionException::CANNOT_ENCRYPT,
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         $internalKeyEncrypted = AsymmetricEncryptionHelper::encryptByPrivateKey($internalKey, $privateKey);
62 62
         try {
63 63
             $dataEncrypted = SymmetricEncryptionHelper::encrypt($data, $internalKey);
64
-        } catch(SymmetricEncryptionException $e) {
64
+        } catch (SymmetricEncryptionException $e) {
65 65
             throw new AsymmetricEncryptionException(
66 66
                 'cannot encrypt',
67 67
                 AsymmetricEncryptionException::CANNOT_ENCRYPT,
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 
91 91
         try {
92 92
             return SymmetricEncryptionHelper::decrypt($dataPartEncrypted, $internalKeyDecrypted);
93
-        } catch(SymmetricEncryptionException $e) {
93
+        } catch (SymmetricEncryptionException $e) {
94 94
             throw new AsymmetricEncryptionException(
95 95
                 'cannot decrypt',
96 96
                 AsymmetricEncryptionException::CANNOT_DECRYPT,
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
         try {
119 119
             return SymmetricEncryptionHelper::decrypt($dataPartEncrypted, $internalKeyDecrypted);
120
-        } catch(SymmetricEncryptionException $e) {
120
+        } catch (SymmetricEncryptionException $e) {
121 121
             throw new AsymmetricEncryptionException(
122 122
                 'cannot decrypt',
123 123
                 AsymmetricEncryptionException::CANNOT_DECRYPT,
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
     protected static function getPrefixMatches(string $dataEncrypted): array
136 136
     {
137 137
         preg_match('/^([0-9]+)_/', $dataEncrypted, $matches);
138
-        if(!isset($matches[1])) {
138
+        if (!isset($matches[1])) {
139 139
             throw new AsymmetricEncryptionException('cannot decrypt', AsymmetricEncryptionException::CANNOT_DECRYPT);
140 140
         }
141 141
         $matches[0] = strlen($matches[0]);
142 142
 
143
-        return [$matches[0], (int)$matches[1]];
143
+        return [$matches[0], (int) $matches[1]];
144 144
     }
145 145
 
146 146
     /**
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
         $charactersLength = strlen($characters);
155 155
         $randomString = '';
156 156
 
157
-        for($i = 0; $i < $length; $i++) {
158
-            $randomString .= $characters[rand(0, $charactersLength - 1)];
157
+        for ($i = 0; $i < $length; $i++) {
158
+            $randomString .= $characters[rand(0, $charactersLength-1)];
159 159
         }
160 160
 
161 161
         return $randomString;
Please login to merge, or discard this patch.