@@ -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 | |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | |
| 166 | 166 | // test different strings when comparing and get time needed |
| 167 | 167 | $result = []; |
| 168 | - foreach(array( |
|
| 169 | - 'length' => [$string1, $string1 . 'a'], |
|
| 168 | + foreach (array( |
|
| 169 | + 'length' => [$string1, $string1.'a'], |
|
| 170 | 170 | 'diff' => [$string1, $string2], |
| 171 | 171 | 'same' => [$string1, $string1] |
| 172 | 172 | ) as $testName => $strings) { |
| 173 | 173 | $timeElapsed = 0; |
| 174 | - for ($i=0; $i < 3; $i++) { |
|
| 174 | + for ($i = 0; $i < 3; $i++) { |
|
| 175 | 175 | $timeElapsed -= microtime(true); |
| 176 | 176 | $comparisonResult = $cryptTool->stringCompare($strings[0], $strings[1]); |
| 177 | 177 | $timeElapsed += microtime(true); |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | // check timings |
| 194 | 194 | echo 'Timing test results with '.$prefix.':'.PHP_EOL; |
| 195 | - $timingRatio = $result['diff'][0] / $result['same'][0]; |
|
| 196 | - $absoluteDifference = abs($result['diff'][0] - $result['same'][0]); |
|
| 195 | + $timingRatio = $result['diff'][0]/$result['same'][0]; |
|
| 196 | + $absoluteDifference = abs($result['diff'][0]-$result['same'][0]); |
|
| 197 | 197 | echo 'timing ratio: '.$timingRatio.PHP_EOL; |
| 198 | 198 | echo 'absolute difference: '.$absoluteDifference.PHP_EOL; |
| 199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function testRemoveVar() { |
| 214 | 214 | $this->doTest(function(CryptTool $cryptTool, $prefix) { |
| 215 | - foreach(array( |
|
| 215 | + foreach (array( |
|
| 216 | 216 | 'hex' => Constants::myPrivateKeyExtract, |
| 217 | 217 | 'bin' => $cryptTool->hex2bin(Constants::myPrivateKeyExtract) |
| 218 | 218 | ) as $key => $testVar) { |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | private function doTest(\Closure $c) { |
| 229 | - foreach(array( |
|
| 229 | + foreach (array( |
|
| 230 | 230 | 'Salt' => CryptTool::createInstance(CryptTool::TYPE_SALT), |
| 231 | 231 | 'Sodium' => CryptTool::createInstance(CryptTool::TYPE_SODIUM) |
| 232 | 232 | ) as $key => $instance) { |
| 233 | 233 | |
| 234 | - if($instance === null) { |
|
| 234 | + if ($instance === null) { |
|
| 235 | 235 | echo $key.": could not instance crypt tool\n"; |
| 236 | 236 | break; |
| 237 | 237 | } |