@@ -78,7 +78,7 @@ |
||
| 78 | 78 | * @return string |
| 79 | 79 | */ |
| 80 | 80 | protected function getErrorMessageByErrorCode($httpCode) { |
| 81 | - switch($httpCode) { |
|
| 81 | + switch ($httpCode) { |
|
| 82 | 82 | case 401: |
| 83 | 83 | return 'API identity or secret incorrect'; |
| 84 | 84 | case 404: |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | protected function getErrorMessageByErrorCode($httpCode) { |
| 35 | - switch($httpCode) { |
|
| 35 | + switch ($httpCode) { |
|
| 36 | 36 | case 401: |
| 37 | 37 | return 'API identity or secret incorrect'; |
| 38 | 38 | case 500: |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | protected function getErrorMessageByErrorCode($httpCode) { |
| 35 | - switch($httpCode) { |
|
| 35 | + switch ($httpCode) { |
|
| 36 | 36 | case 400: |
| 37 | 37 | return 'Hash length is wrong'; |
| 38 | 38 | case 401: |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * @return null|int |
| 37 | 37 | */ |
| 38 | 38 | final public function getErrorCode() { |
| 39 | - if(false === $this->isSuccess()) { |
|
| 39 | + if (false === $this->isSuccess()) { |
|
| 40 | 40 | return $this->httpCode; |
| 41 | 41 | } |
| 42 | 42 | return null; |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | 31 | protected function getErrorMessageByErrorCode($httpCode) { |
| 32 | - switch($httpCode) { |
|
| 32 | + switch ($httpCode) { |
|
| 33 | 33 | case 400: |
| 34 | 34 | return 'The recipient identity is invalid or the account is not set up for E2E mode'; |
| 35 | 35 | case 401: |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | protected function getErrorMessageByErrorCode($httpCode) { |
| 35 | - switch($httpCode) { |
|
| 35 | + switch ($httpCode) { |
|
| 36 | 36 | case 400: |
| 37 | 37 | return 'The recipient identity is invalid or the account is not set up for simple mode'; |
| 38 | 38 | case 401: |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | 36 | protected function getErrorMessageByErrorCode($httpCode) { |
| 37 | - switch($httpCode) { |
|
| 37 | + switch ($httpCode) { |
|
| 38 | 38 | case 401: |
| 39 | 39 | return 'API identity or secret incorrect or file is empty'; |
| 40 | 40 | case 402: |
@@ -247,8 +247,7 @@ |
||
| 247 | 247 | |
| 248 | 248 | $receiveResult->addFile('image', $filePath); |
| 249 | 249 | } |
| 250 | - } |
|
| 251 | - else if($message instanceof FileMessage) { |
|
| 250 | + } else if($message instanceof FileMessage) { |
|
| 252 | 251 | $result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage); |
| 253 | 252 | |
| 254 | 253 | if(null !== $result && true === $result->isSuccess()) { |
@@ -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 | 227 | $receiveResult = new ReceiveMessageResult($messageId, $message); |
| 228 | 228 | |
| 229 | - if($outputFolder === false) { |
|
| 229 | + if ($outputFolder === false) { |
|
| 230 | 230 | return $receiveResult; |
| 231 | 231 | } |
| 232 | - if($outputFolder === null || strlen($outputFolder) == 0) { |
|
| 232 | + if ($outputFolder === null || strlen($outputFolder) == 0) { |
|
| 233 | 233 | $outputFolder = '.'; |
| 234 | 234 | } |
| 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 | $this->cryptTool->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 |
@@ -327,14 +327,14 @@ discard block |
||
| 327 | 327 | //fetch the public key |
| 328 | 328 | $receiverPublicKey = $this->connection->fetchPublicKey($threemaId); |
| 329 | 329 | |
| 330 | - if(null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
| 330 | + if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { |
|
| 331 | 331 | throw new Exception('Invalid threema id'); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if(null !== $capabilityCheck) { |
|
| 334 | + if (null !== $capabilityCheck) { |
|
| 335 | 335 | //check capability |
| 336 | 336 | $capability = $this->connection->keyCapability($threemaId); |
| 337 | - if(null === $capability || false === $capabilityCheck->__invoke($capability)) { |
|
| 337 | + if (null === $capability || false === $capabilityCheck->__invoke($capability)) { |
|
| 338 | 338 | throw new Exception('threema id does not have the capability'); |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | * @throws Exception |
| 351 | 351 | */ |
| 352 | 352 | private final function downloadFile(ThreemaMessage $message, $blobId, \Closure $downloadMessage = null) { |
| 353 | - if(null === $downloadMessage |
|
| 353 | + if (null === $downloadMessage |
|
| 354 | 354 | || true === $downloadMessage->__invoke($message, $blobId)) { |
| 355 | 355 | //make a download |
| 356 | 356 | $result = $this->connection->downloadFile($blobId); |
| 357 | - if(null === $result || false === $result->isSuccess()) { |
|
| 357 | + if (null === $result || false === $result->isSuccess()) { |
|
| 358 | 358 | throw new Exception('could not download the file with blob id '.$blobId); |
| 359 | 359 | } |
| 360 | 360 | |
@@ -27,12 +27,12 @@ |
||
| 27 | 27 | * @return string|null |
| 28 | 28 | */ |
| 29 | 29 | public final function getPublicKey($threemaId) { |
| 30 | - if(array_key_exists($threemaId, $this->cache)) { |
|
| 30 | + if (array_key_exists($threemaId, $this->cache)) { |
|
| 31 | 31 | return $this->cache[$threemaId]; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $publicKey = $this->findPublicKey($threemaId); |
| 35 | - if(null !== $publicKey) { |
|
| 35 | + if (null !== $publicKey) { |
|
| 36 | 36 | $this->cache[$threemaId] = $publicKey; |
| 37 | 37 | } |
| 38 | 38 | return $publicKey; |