@@ -76,7 +76,7 @@ |
||
76 | 76 | * @param object $res |
77 | 77 | * @return SendE2EResult |
78 | 78 | */ |
79 | - public function parseResult($httpCode, $res){ |
|
79 | + public function parseResult($httpCode, $res) { |
|
80 | 80 | return new SendE2EResult($httpCode, $res); |
81 | 81 | } |
82 | 82 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | * @param object $res |
77 | 77 | * @return SendE2EResult |
78 | 78 | */ |
79 | - public function parseResult($httpCode, $res){ |
|
79 | + public function parseResult($httpCode, $res) { |
|
80 | 80 | return new SendE2EResult($httpCode, $res); |
81 | 81 | } |
82 | 82 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $this->cryptTool = $cryptTool; |
43 | 43 | $this->privateKey = $privateKey; |
44 | 44 | |
45 | - if(null === $this->cryptTool) { |
|
45 | + if (null === $this->cryptTool) { |
|
46 | 46 | $this->cryptTool = CryptTool::getInstance(); |
47 | 47 | } |
48 | 48 | } |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | //analyse the file |
85 | 85 | $fileAnalyzeResult = FileAnalysisTool::analyse($imagePath); |
86 | 86 | |
87 | - if(null === $fileAnalyzeResult) { |
|
87 | + if (null === $fileAnalyzeResult) { |
|
88 | 88 | throw new Exception('could not analyze the file'); |
89 | 89 | } |
90 | 90 | |
91 | - if(false === in_array($fileAnalyzeResult->getMimeType(), array( |
|
91 | + if (false === in_array($fileAnalyzeResult->getMimeType(), array( |
|
92 | 92 | 'image/jpg', |
93 | 93 | 'image/jpeg', |
94 | 94 | 'image/png' ))) { |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | //encrypt the image file |
104 | 104 | $encryptionResult = $this->cryptTool->encryptImage(file_get_contents($imagePath), $this->privateKey, $receiverPublicKey); |
105 | - $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
105 | + $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
106 | 106 | |
107 | - if($uploadResult === null || !$uploadResult->isSuccess()) { |
|
107 | + if ($uploadResult === null || !$uploadResult->isSuccess()) { |
|
108 | 108 | throw new Exception('could not upload the image ('.$uploadResult->getErrorCode().' '.$uploadResult->getErrorMessage().') '.$uploadResult->getRawResponse()); |
109 | 109 | } |
110 | 110 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | //analyse the file |
135 | 135 | $fileAnalyzeResult = FileAnalysisTool::analyse($filePath); |
136 | 136 | |
137 | - if(null === $fileAnalyzeResult) { |
|
137 | + if (null === $fileAnalyzeResult) { |
|
138 | 138 | throw new Exception('could not analyze the file'); |
139 | 139 | } |
140 | 140 | |
@@ -145,21 +145,21 @@ discard block |
||
145 | 145 | |
146 | 146 | //encrypt the main file |
147 | 147 | $encryptionResult = $this->cryptTool->encryptFile(file_get_contents($filePath)); |
148 | - $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
148 | + $uploadResult = $this->connection->uploadFile($encryptionResult->getData()); |
|
149 | 149 | |
150 | - if($uploadResult === null || !$uploadResult->isSuccess()) { |
|
150 | + if ($uploadResult === null || !$uploadResult->isSuccess()) { |
|
151 | 151 | throw new Exception('could not upload the file ('.$uploadResult->getErrorCode().' '.$uploadResult->getErrorMessage().') '.$uploadResult->getRawResponse()); |
152 | 152 | } |
153 | 153 | |
154 | 154 | $thumbnailUploadResult = null; |
155 | 155 | |
156 | 156 | //encrypt the thumbnail file (if exists) |
157 | - if(strlen($thumbnailPath) > 0 && true === file_exists($thumbnailPath)) { |
|
157 | + if (strlen($thumbnailPath) > 0 && true === file_exists($thumbnailPath)) { |
|
158 | 158 | //encrypt the main file |
159 | 159 | $thumbnailEncryptionResult = $this->cryptTool->encryptFileThumbnail(file_get_contents($thumbnailPath), $encryptionResult->getKey()); |
160 | 160 | $thumbnailUploadResult = $this->connection->uploadFile($thumbnailEncryptionResult->getData()); |
161 | 161 | |
162 | - if($thumbnailUploadResult === null || !$thumbnailUploadResult->isSuccess()) { |
|
162 | + if ($thumbnailUploadResult === null || !$thumbnailUploadResult->isSuccess()) { |
|
163 | 163 | throw new Exception('could not upload the thumbnail file ('.$thumbnailUploadResult->getErrorCode().' '.$thumbnailUploadResult->getErrorMessage().') '.$thumbnailUploadResult->getRawResponse()); |
164 | 164 | } |
165 | 165 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | //fetch the public key |
210 | 210 | $receiverPublicKey = $this->connection->fetchPublicKey($threemaId); |
211 | 211 | |
212 | - if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
212 | + if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
213 | 213 | throw new Exception('Invalid threema id'); |
214 | 214 | } |
215 | 215 | |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | $nonce |
221 | 221 | ); |
222 | 222 | |
223 | - if(null === $message || false === is_object($message)) { |
|
223 | + if (null === $message || false === is_object($message)) { |
|
224 | 224 | throw new Exception('Could not encrypt box'); |
225 | 225 | } |
226 | 226 | |
227 | - if($outputFolder === false) { |
|
227 | + if ($outputFolder === false) { |
|
228 | 228 | return $receiveResult; |
229 | 229 | } |
230 | - if($outputFolder === null || strlen($outputFolder) == 0) { |
|
230 | + if ($outputFolder === null || strlen($outputFolder) == 0) { |
|
231 | 231 | $outputFolder = '.'; |
232 | 232 | } |
233 | 233 | |
234 | 234 | $receiveResult = new ReceiveMessageResult($messageId, $message); |
235 | 235 | |
236 | - if($message instanceof ImageMessage) { |
|
236 | + if ($message instanceof ImageMessage) { |
|
237 | 237 | $result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage); |
238 | - if(null !== $result && true === $result->isSuccess()) { |
|
238 | + if (null !== $result && true === $result->isSuccess()) { |
|
239 | 239 | $image = $this->cryptTool->decryptImage( |
240 | 240 | $result->getData(), |
241 | 241 | $this->cryptTool->hex2bin($receiverPublicKey->getPublicKey()), |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | throw new Exception('decryption of image failed'); |
248 | 248 | } |
249 | 249 | //save file |
250 | - $filePath = $outputFolder . '/' . $messageId . '.jpg'; |
|
250 | + $filePath = $outputFolder.'/'.$messageId.'.jpg'; |
|
251 | 251 | $f = fopen($filePath, 'w+'); |
252 | 252 | fwrite($f, $image); |
253 | 253 | fclose($f); |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | $receiveResult->addFile('image', $filePath); |
256 | 256 | } |
257 | 257 | } |
258 | - else if($message instanceof FileMessage) { |
|
258 | + else if ($message instanceof FileMessage) { |
|
259 | 259 | $result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage); |
260 | 260 | |
261 | - if(null !== $result && true === $result->isSuccess()) { |
|
261 | + if (null !== $result && true === $result->isSuccess()) { |
|
262 | 262 | $file = $this->cryptTool->decryptFile( |
263 | 263 | $result->getData(), |
264 | 264 | hex2bin($message->getEncryptionKey())); |
@@ -268,20 +268,20 @@ discard block |
||
268 | 268 | } |
269 | 269 | |
270 | 270 | //save file |
271 | - $filePath = $outputFolder . '/' . $messageId . '-' . $message->getFilename(); |
|
271 | + $filePath = $outputFolder.'/'.$messageId.'-'.$message->getFilename(); |
|
272 | 272 | file_put_contents($filePath, $file); |
273 | 273 | |
274 | 274 | $receiveResult->addFile('file', $filePath); |
275 | 275 | } |
276 | 276 | |
277 | - if(null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) { |
|
277 | + if (null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) { |
|
278 | 278 | $result = $this->downloadFile($message, $message->getThumbnailBlobId(), $downloadMessage); |
279 | - if(null !== $result && true === $result->isSuccess()) { |
|
279 | + if (null !== $result && true === $result->isSuccess()) { |
|
280 | 280 | $file = $this->cryptTool->decryptFileThumbnail( |
281 | 281 | $result->getData(), |
282 | 282 | $this->cryptTool->hex2bin($message->getEncryptionKey())); |
283 | 283 | |
284 | - if(null === $file) { |
|
284 | + if (null === $file) { |
|
285 | 285 | throw new Exception('thumbnail decryption failed'); |
286 | 286 | } |
287 | 287 | //save file |
@@ -308,14 +308,14 @@ discard block |
||
308 | 308 | //fetch the public key |
309 | 309 | $receiverPublicKey = $this->connection->fetchPublicKey($threemaId); |
310 | 310 | |
311 | - if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
311 | + if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
312 | 312 | throw new Exception('Invalid threema id'); |
313 | 313 | } |
314 | 314 | |
315 | - if(null !== $capabilityCheck) { |
|
315 | + if (null !== $capabilityCheck) { |
|
316 | 316 | //check capability |
317 | 317 | $capability = $this->connection->keyCapability($threemaId); |
318 | - if(null === $capability || false === $capabilityCheck->__invoke($capability)) { |
|
318 | + if (null === $capability || false === $capabilityCheck->__invoke($capability)) { |
|
319 | 319 | throw new Exception('threema id does not have the capability'); |
320 | 320 | } |
321 | 321 | } |
@@ -331,11 +331,11 @@ discard block |
||
331 | 331 | * @throws Exception |
332 | 332 | */ |
333 | 333 | private final function downloadFile(ThreemaMessage $message, $blobId, \Closure $downloadMessage = null) { |
334 | - if(null === $downloadMessage |
|
334 | + if (null === $downloadMessage |
|
335 | 335 | || true === $downloadMessage->__invoke($message, $blobId)) { |
336 | 336 | //make a download |
337 | 337 | $result = $this->connection->downloadFile($blobId); |
338 | - if(null === $result || false === $result->isSuccess()) { |
|
338 | + if (null === $result || false === $result->isSuccess()) { |
|
339 | 339 | throw new Exception('could not download the file with blob id '.$blobId); |
340 | 340 | } |
341 | 341 |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | $this->assertNotNull($message); |
58 | 58 | $this->assertTrue($message instanceof TextMessage); |
59 | - if($message instanceof TextMessage) { |
|
59 | + if ($message instanceof TextMessage) { |
|
60 | 60 | $this->assertEquals($message->getText(), 'Dies ist eine Testnachricht. äöü'); |
61 | 61 | } |
62 | 62 | }); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | |
94 | 94 | public function testDerivePublicKey() { |
95 | - $this->doTest(function(CryptTool $cryptTool, $prefix){ |
|
95 | + $this->doTest(function(CryptTool $cryptTool, $prefix) { |
|
96 | 96 | $publicKey = $cryptTool->derivePublicKey($cryptTool->hex2bin(Common::getPrivateKey(Constants::myPrivateKey))); |
97 | 97 | $myPublicKey = $cryptTool->hex2bin(Common::getPublicKey(Constants::myPublicKey)); |
98 | 98 | |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | $timeElapsed = []; |
168 | 168 | $comparisonResult = []; |
169 | 169 | $timeElapsedAvg = []; |
170 | - foreach(array( |
|
171 | - 'length' => [$string1, $string1 . 'a'], |
|
170 | + foreach (array( |
|
171 | + 'length' => [$string1, $string1.'a'], |
|
172 | 172 | 'diff' => [$string1, $string2], |
173 | 173 | 'same' => [$string1, $string1] |
174 | 174 | ) as $testName => $strings) { |
175 | 175 | $timeMin = [null, 0]; |
176 | 176 | $timeMax = [null, 0]; |
177 | - for ($i=0; $i < 3; $i++) { |
|
177 | + for ($i = 0; $i < 3; $i++) { |
|
178 | 178 | // test run with delay |
179 | 179 | $timeElapsed[$testName][$i] = -microtime(true); |
180 | 180 | $comparisonResult[$testName][$i] = $cryptTool->stringCompare($strings[0], $strings[1]); |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | array_splice($timeElapsed[$testName], $timeMax[1] >= $timeMin[1] ? ($timeMax[1]-1) : $timeMax[1], 1); |
208 | 208 | |
209 | 209 | // calculate average (currently useless as there is only one value left, but it may be useful later) |
210 | - $timeElapsedAvg[$testName] = array_sum($timeElapsed[$testName]) / count($timeElapsed[$testName]); |
|
210 | + $timeElapsedAvg[$testName] = array_sum($timeElapsed[$testName])/count($timeElapsed[$testName]); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // check timings |
214 | 214 | echo 'Timing test results with '.$prefix.':'.PHP_EOL; |
215 | - $timingRatio = $timeElapsedAvg['diff'] / $timeElapsedAvg['same']; |
|
216 | - $absoluteDifference = abs($timeElapsedAvg['diff'] - $timeElapsedAvg['same']); |
|
215 | + $timingRatio = $timeElapsedAvg['diff']/$timeElapsedAvg['same']; |
|
216 | + $absoluteDifference = abs($timeElapsedAvg['diff']-$timeElapsedAvg['same']); |
|
217 | 217 | echo 'timing ratio: '.$timingRatio.PHP_EOL; |
218 | 218 | echo 'absolute difference: '.$absoluteDifference.PHP_EOL; |
219 | 219 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $allowedDifferenceLow = 0.25; |
222 | 222 | $allowedDifferenceTop = 0.5; |
223 | 223 | // double value if running in a CI envoriment |
224 | - if (getenv('CI') == 'true') { |
|
224 | + if (getenv('CI') == 'true') { |
|
225 | 225 | $allowedDifferenceLow = $allowedDifferenceLow*2; |
226 | 226 | $allowedDifferenceTop = $allowedDifferenceTop*2; |
227 | 227 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function testRemoveVar() { |
241 | 241 | $this->doTest(function(CryptTool $cryptTool, $prefix) { |
242 | - foreach(array( |
|
242 | + foreach (array( |
|
243 | 243 | 'hex' => Constants::myPrivateKeyExtract, |
244 | 244 | 'bin' => $cryptTool->hex2bin(Constants::myPrivateKeyExtract) |
245 | 245 | ) as $key => $testVar) { |
@@ -253,12 +253,12 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | private function doTest(\Closure $c) { |
256 | - foreach(array( |
|
256 | + foreach (array( |
|
257 | 257 | 'Salt' => CryptTool::createInstance(CryptTool::TYPE_SALT), |
258 | 258 | 'Sodium' => CryptTool::createInstance(CryptTool::TYPE_SODIUM) |
259 | 259 | ) as $key => $instance) { |
260 | 260 | |
261 | - if($instance === null) { |
|
261 | + if ($instance === null) { |
|
262 | 262 | echo $key.": could not instance crypt tool\n"; |
263 | 263 | break; |
264 | 264 | } |