Passed
Pull Request — develop (#50)
by Pieter van der
03:28
created
library/tiqr/Tiqr/UserSecretStorage/Encryption/OpenSSL.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@
 block discarded – undo
160 160
     }
161 161
     
162 162
     /**
163
-      * Decrypts the given data.
163
+     * Decrypts the given data.
164 164
      *
165 165
      * @param string $data Data to decrypt.
166 166
      * @return string decrypted data
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
     */
49 49
 
50 50
     private $_supportedCiphers = [
51
-        'aes-128-cbc' => [ 'tag' => false, 'key' => 16 ],
52
-        'aes-128-gcm' => [ 'tag' => true, 'key' => 16 ],
53
-        'aes-192-cbc' => [ 'tag' => false, 'key' => 24 ],
54
-        'aes-192-gcm' => [ 'tag' => true, 'key' => 24 ],
55
-        'aes-256-cbc' => [ 'tag' => false, 'key' => 32 ],
56
-        'aes-256-gcm' => [ 'tag' => true, 'key' => 32 ],
57
-        'chacha20' => [ 'tag' => false, 'key' => 32 ],
58
-        'chacha20-poly1305' => [ 'tag' => false, 'key' => 32 ],
59
-        'camellia-128-cbc' => [ 'tag' => false, 'key' => 16 ],
60
-        'camellia-192-cbc' => [ 'tag' => false, 'key' => 24 ],
61
-        'camellia-256-cbc' => [ 'tag' => false, 'key' => 32 ],
62
-        'aria-128-cbc' => [ 'tag' => false, 'key' => 16 ],
63
-        'aria-128-gcm' => [ 'tag' => true, 'key' => 16 ],
64
-        'aria-192-cbc' => [ 'tag' => false, 'key' => 24 ],
65
-        'aria-192-gcm' => [ 'tag' => true, 'key' => 24 ],
66
-        'aria-256-cbc' => [ 'tag' => false, 'key' => 32 ],
67
-        'aria-256-gcm' => [ 'tag' => true, 'key' => 32 ],
51
+        'aes-128-cbc' => ['tag' => false, 'key' => 16],
52
+        'aes-128-gcm' => ['tag' => true, 'key' => 16],
53
+        'aes-192-cbc' => ['tag' => false, 'key' => 24],
54
+        'aes-192-gcm' => ['tag' => true, 'key' => 24],
55
+        'aes-256-cbc' => ['tag' => false, 'key' => 32],
56
+        'aes-256-gcm' => ['tag' => true, 'key' => 32],
57
+        'chacha20' => ['tag' => false, 'key' => 32],
58
+        'chacha20-poly1305' => ['tag' => false, 'key' => 32],
59
+        'camellia-128-cbc' => ['tag' => false, 'key' => 16],
60
+        'camellia-192-cbc' => ['tag' => false, 'key' => 24],
61
+        'camellia-256-cbc' => ['tag' => false, 'key' => 32],
62
+        'aria-128-cbc' => ['tag' => false, 'key' => 16],
63
+        'aria-128-gcm' => ['tag' => true, 'key' => 16],
64
+        'aria-192-cbc' => ['tag' => false, 'key' => 24],
65
+        'aria-192-gcm' => ['tag' => true, 'key' => 24],
66
+        'aria-256-cbc' => ['tag' => false, 'key' => 32],
67
+        'aria-256-gcm' => ['tag' => true, 'key' => 32],
68 68
     ];
69 69
 
70 70
     /**
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
         // A longer key is not a problem, but could indicate a configuration error
138 138
         $key_length = $this->_supportedCiphers[$this->_cipher]['key'];
139 139
         if (strlen($key) != $key_length) {
140
-            throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got " . strlen($key) . " bytes");
140
+            throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got ".strlen($key)." bytes");
141 141
         }
142 142
 
143 143
         // openssl_encrypt returns the ciphertext as a base64 encoded string, so we don't need to encode it again
144 144
         // The tag is returned as a binary string, but only if the cipher requires a tag
145
-        $tag='';
145
+        $tag = '';
146 146
         if ($this->_supportedCiphers[$this->_cipher]['tag']) {
147 147
             $encrypted = openssl_encrypt($data, $this->_cipher, $key, 0, $iv, $tag, '', 16);
148 148
         } else {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
         $tag = $this->_supportedCiphers[$this->_cipher]['tag'] ? $tag : '';
155 155
         // Return the encoded ciphertext, including the IV, tag and cipher
156 156
         // <cipher>:<key_id>:iv<>:<tag>:<ciphertext>
157
-        $encoded = $this->_cipher . ":" . $this->_key_id . ":" . base64_encode($iv) . ":" . base64_encode($tag) . ":" . $encrypted;
157
+        $encoded = $this->_cipher.":".$this->_key_id.":".base64_encode($iv).":".base64_encode($tag).":".$encrypted;
158 158
 
159 159
         return $encoded;
160 160
     }
@@ -193,19 +193,19 @@  discard block
 block discarded – undo
193 193
         }
194 194
 
195 195
         // IV
196
-        $iv = base64_decode($split_data[2],true);
196
+        $iv = base64_decode($split_data[2], true);
197 197
         if ($iv === false) {
198 198
             throw new RuntimeException("Error decoding IV");
199 199
         }
200 200
 
201 201
         // Tag
202
-        $tag = base64_decode($split_data[3],true);
202
+        $tag = base64_decode($split_data[3], true);
203 203
         if ($tag === false) {
204 204
             throw new RuntimeException("Error decoding tag");
205 205
         }
206 206
         $ciphertext = $split_data[4];
207 207
 
208
-        $plaintext=openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag);
208
+        $plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag);
209 209
         if ($plaintext === false) {
210 210
             throw new RuntimeException("Error decrypting data");
211 211
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Encryption/Plain.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
     }
58 58
     
59 59
     /**
60
-      * Decrypts the given data.
60
+     * Decrypts the given data.
61 61
      *
62 62
      * @param String $data Data to decrypt.
63 63
      *
Please login to merge, or discard this patch.