@@ -49,20 +49,20 @@ |
||
49 | 49 | $this->host = $host; |
50 | 50 | |
51 | 51 | // TLS options |
52 | - if(null !== $tlsOptions && is_array($tlsOptions)) { |
|
53 | - if(true === array_key_exists(self::tlsOptionForceHttps, $tlsOptions)) { |
|
52 | + if (null !== $tlsOptions && is_array($tlsOptions)) { |
|
53 | + if (true === array_key_exists(self::tlsOptionForceHttps, $tlsOptions)) { |
|
54 | 54 | $this->tlsOptions[self::tlsOptionForceHttps] = $tlsOptions[self::tlsOptionForceHttps] === true; |
55 | 55 | } |
56 | 56 | |
57 | - if(true === array_key_exists(self::tlsOptionVersion, $tlsOptions)) { |
|
57 | + if (true === array_key_exists(self::tlsOptionVersion, $tlsOptions)) { |
|
58 | 58 | $this->tlsOptions[self::tlsOptionVersion] = $tlsOptions[self::tlsOptionVersion]; |
59 | 59 | } |
60 | 60 | |
61 | - if(true === array_key_exists(self::tlsOptionCipher, $tlsOptions)) { |
|
61 | + if (true === array_key_exists(self::tlsOptionCipher, $tlsOptions)) { |
|
62 | 62 | $this->tlsOptions[self::tlsOptionCipher] = $tlsOptions[self::tlsOptionCipher]; |
63 | 63 | } |
64 | 64 | |
65 | - if(true === array_key_exists(self::tlsOptionPinnedKey, $tlsOptions)) { |
|
65 | + if (true === array_key_exists(self::tlsOptionPinnedKey, $tlsOptions)) { |
|
66 | 66 | $this->tlsOptions[self::tlsOptionPinnedKey] = $tlsOptions[self::tlsOptionPinnedKey]; |
67 | 67 | } |
68 | 68 | } |
@@ -2,11 +2,11 @@ discard block |
||
2 | 2 | require_once("Salt/autoload.php"); |
3 | 3 | |
4 | 4 | //define possibly missing constants |
5 | -defined('CURL_SSLVERSION_DEFAULT') || define('CURL_SSLVERSION_DEFAULT', 0); |
|
6 | -defined('CURL_SSLVERSION_TLSv1') || define('CURL_SSLVERSION_TLSv1', 1); |
|
7 | -defined('CURL_SSLVERSION_TLSv1_1') || define('CURL_SSLVERSION_TLSv1_1', 5); |
|
8 | -defined('CURL_SSLVERSION_TLSv1_2') || define('CURL_SSLVERSION_TLSv1_2', 6); |
|
9 | -defined('CURLOPT_PINNEDPUBLICKEY') || define('CURLOPT_PINNEDPUBLICKEY', 10230); |
|
5 | +defined('CURL_SSLVERSION_DEFAULT') || define('CURL_SSLVERSION_DEFAULT', 0); |
|
6 | +defined('CURL_SSLVERSION_TLSv1') || define('CURL_SSLVERSION_TLSv1', 1); |
|
7 | +defined('CURL_SSLVERSION_TLSv1_1') || define('CURL_SSLVERSION_TLSv1_1', 5); |
|
8 | +defined('CURL_SSLVERSION_TLSv1_2') || define('CURL_SSLVERSION_TLSv1_2', 6); |
|
9 | +defined('CURLOPT_PINNEDPUBLICKEY') || define('CURLOPT_PINNEDPUBLICKEY', 10230); |
|
10 | 10 | |
11 | 11 | //define autoloader |
12 | 12 | $d = dirname(__FILE__); |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | $fileName = ''; |
17 | 17 | if ($lastNsPos = strrpos($className, '\\')) { |
18 | 18 | $namespace = substr($className, 0, $lastNsPos); |
19 | - $className = substr($className, $lastNsPos + 1); |
|
20 | - $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; |
|
19 | + $className = substr($className, $lastNsPos+1); |
|
20 | + $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR; |
|
21 | 21 | } |
22 | - $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; |
|
22 | + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className).'.php'; |
|
23 | 23 | |
24 | - if(true === file_exists( $d.'/'.$fileName)) { |
|
24 | + if (true === file_exists($d.'/'.$fileName)) { |
|
25 | 25 | require $d.'/'.$fileName; |
26 | 26 | } |
27 | 27 | }); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | define('MSGAPI_SDK_VERSION', $sdkVersion); |
31 | 31 | $cryptTool = Threema\MsgApi\Tools\CryptTool::getInstance(); |
32 | 32 | |
33 | -if(null === $cryptTool) { |
|
33 | +if (null === $cryptTool) { |
|
34 | 34 | throw new \Threema\Core\Exception("no supported crypt-tool"); |
35 | 35 | } |
36 | 36 |
@@ -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,8 +42,8 @@ discard block |
||
42 | 42 | * @return CryptTool |
43 | 43 | */ |
44 | 44 | public static function getInstance() { |
45 | - if(null === self::$instance) { |
|
46 | - foreach(array( |
|
45 | + if (null === self::$instance) { |
|
46 | + foreach (array( |
|
47 | 47 | function() { |
48 | 48 | return self::createInstance(self::TYPE_SODIUM); |
49 | 49 | }, |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | return self::createInstance(self::TYPE_SALT); |
52 | 52 | }) as $instanceGenerator) { |
53 | 53 | $i = $instanceGenerator->__invoke(); |
54 | - if(null !== $i) { |
|
54 | + if (null !== $i) { |
|
55 | 55 | self::$instance = $i; |
56 | 56 | break; |
57 | 57 | } |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | * @return null|CryptTool null on unknown type |
67 | 67 | */ |
68 | 68 | public static function createInstance($type) { |
69 | - switch($type) { |
|
69 | + switch ($type) { |
|
70 | 70 | case self::TYPE_SODIUM: |
71 | 71 | $instance = new CryptToolSodium(); |
72 | - if(false === $instance->isSupported()) { |
|
72 | + if (false === $instance->isSupported()) { |
|
73 | 73 | //try to instance old version of sodium wrapper |
74 | 74 | /** @noinspection PhpDeprecationInspection */ |
75 | 75 | $instance = new CryptToolSodiumDep(); |
76 | 76 | } |
77 | - return $instance->isSupported() ? $instance :null; |
|
77 | + return $instance->isSupported() ? $instance : null; |
|
78 | 78 | case self::TYPE_SALT: |
79 | 79 | $instance = new CryptToolSalt(); |
80 | - return $instance->isSupported() ? $instance :null; |
|
80 | + return $instance->isSupported() ? $instance : null; |
|
81 | 81 | default: |
82 | 82 | return null; |
83 | 83 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | final public function encryptMessageText($text, $senderPrivateKey, $recipientPublicKey, $nonce) { |
107 | 107 | /* prepend type byte (0x01) to message data */ |
108 | - $textBytes = "\x01" . $text; |
|
108 | + $textBytes = "\x01".$text; |
|
109 | 109 | |
110 | 110 | /* determine random amount of PKCS7 padding */ |
111 | 111 | $padbytes = $this->generatePadBytes(); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $senderPrivateKey, |
131 | 131 | $recipientPublicKey, |
132 | 132 | $nonce) { |
133 | - $message = "\x02" . $this->hex2bin($uploadFileResult->getBlobId()); |
|
133 | + $message = "\x02".$this->hex2bin($uploadFileResult->getBlobId()); |
|
134 | 134 | $message .= pack('V', $encryptResult->getSize()); |
135 | 135 | $message .= $encryptResult->getNonce(); |
136 | 136 | |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | 'i' => 0 |
162 | 162 | ); |
163 | 163 | |
164 | - if($thumbnailUploadFileResult !== null && strlen($thumbnailUploadFileResult->getBlobId()) > 0) { |
|
164 | + if ($thumbnailUploadFileResult !== null && strlen($thumbnailUploadFileResult->getBlobId()) > 0) { |
|
165 | 165 | $messageContent['t'] = $thumbnailUploadFileResult->getBlobId(); |
166 | 166 | } |
167 | 167 | |
168 | - $message = "\x17" . json_encode($messageContent); |
|
168 | + $message = "\x17".json_encode($messageContent); |
|
169 | 169 | |
170 | 170 | /* determine random amount of PKCS7 padding */ |
171 | 171 | $padbytes = $this->generatePadBytes(); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | /* remove padding */ |
240 | 240 | $padbytes = ord($data[strlen($data)-1]); |
241 | - $realDataLength = strlen($data) - $padbytes; |
|
241 | + $realDataLength = strlen($data)-$padbytes; |
|
242 | 242 | if ($realDataLength < 1) { |
243 | 243 | throw new BadMessageException(); |
244 | 244 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | return new TextMessage(substr($data, 1)); |
265 | 265 | case DeliveryReceipt::TYPE_CODE: |
266 | 266 | /* Delivery receipt */ |
267 | - if ($realDataLength < (self::MESSAGE_ID_LEN-2) || (($realDataLength - 2) % self::MESSAGE_ID_LEN) != 0) { |
|
267 | + if ($realDataLength < (self::MESSAGE_ID_LEN-2) || (($realDataLength-2)%self::MESSAGE_ID_LEN) != 0) { |
|
268 | 268 | throw new BadMessageException(); |
269 | 269 | } |
270 | 270 | |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | return new DeliveryReceipt($receiptType, $messageIds); |
275 | 275 | case ImageMessage::TYPE_CODE: |
276 | 276 | /* Image Message */ |
277 | - if ($realDataLength != 1 + self::BLOB_ID_LEN + self::IMAGE_FILE_SIZE_LEN + self::IMAGE_NONCE_LEN) { |
|
277 | + if ($realDataLength != 1+self::BLOB_ID_LEN+self::IMAGE_FILE_SIZE_LEN+self::IMAGE_NONCE_LEN) { |
|
278 | 278 | throw new BadMessageException(); |
279 | 279 | } |
280 | 280 | |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | case FileMessage::TYPE_CODE: |
286 | 286 | /* Image Message */ |
287 | 287 | $decodeResult = json_decode(substr($data, 1), true); |
288 | - if(null === $decodeResult || false === $decodeResult) { |
|
288 | + if (null === $decodeResult || false === $decodeResult) { |
|
289 | 289 | throw new BadMessageException(); |
290 | 290 | } |
291 | 291 | |
292 | 292 | $values = AssocArray::byJsonString(substr($data, 1), array('b', 't', 'k', 'm', 'n', 's')); |
293 | - if(null === $values) { |
|
293 | + if (null === $values) { |
|
294 | 294 | throw new BadMessageException(); |
295 | 295 | } |
296 | 296 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @return null|string |
393 | 393 | */ |
394 | 394 | public final function decryptFile($data, $key) { |
395 | - $result = $this->openSecretBox($data, self::FILE_NONCE, $key); |
|
395 | + $result = $this->openSecretBox($data, self::FILE_NONCE, $key); |
|
396 | 396 | return false === $result ? null : $result; |
397 | 397 | } |
398 | 398 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | */ |
404 | 404 | public final function encryptFileThumbnail($data, $key) { |
405 | 405 | $box = $this->makeSecretBox($data, self::FILE_THUMBNAIL_NONCE, $key); |
406 | - return new EncryptResult($box, $key, self::FILE_THUMBNAIL_NONCE, strlen($box)); |
|
406 | + return new EncryptResult($box, $key, self::FILE_THUMBNAIL_NONCE, strlen($box)); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | public final function decryptFileThumbnail($data, $key) { |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | */ |
451 | 451 | private function generatePadBytes() { |
452 | 452 | $padbytes = 0; |
453 | - while($padbytes < 1 || $padbytes > 255) { |
|
453 | + while ($padbytes < 1 || $padbytes > 255) { |
|
454 | 454 | $padbytes = ord($this->createRandom(1)); |
455 | 455 | } |
456 | 456 | return $padbytes; |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |