Completed
Push — master ( 382c63...5355c1 )
by rugk
02:29
created
source/Threema/MsgApi/Commands/Credits.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 	 * @param object $res
28 28
 	 * @return CreditsResult
29 29
 	 */
30
-	public function parseResult($httpCode, $res){
30
+	public function parseResult($httpCode, $res) {
31 31
 		return new CreditsResult($httpCode, $res);
32 32
 	}
33 33
 }
Please login to merge, or discard this patch.
source/Threema/MsgApi/Commands/SendE2E.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/CryptTool.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
scripts/buildPhar.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 <?php
3 3
 // set variables
4 4
 $dir = dirname(__DIR__);
5
-$source = dirname(__DIR__) . '/source';
6
-$file = $dir . '/threema_msgapi.phar';
5
+$source = dirname(__DIR__).'/source';
6
+$file = $dir.'/threema_msgapi.phar';
7 7
 
8 8
 // preparation
9 9
 if (!is_dir($dir)) {
Please login to merge, or discard this patch.
source/Threema/Console/Command/Base.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @return int
70 70
 	 */
71 71
 	public function getAllArgumentsCount() {
72
-		return $this->getRequiredArgumentCount() + (null !== $this->optionalArguments ? count($this->optionalArguments) : 0);
72
+		return $this->getRequiredArgumentCount()+(null !== $this->optionalArguments ? count($this->optionalArguments) : 0);
73 73
 	}
74 74
 
75 75
 	/**
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
 	 * @return int
78 78
 	 * @throws \Threema\Core\Exception
79 79
 	 */
80
-	private function getIndexByPos($pos){
80
+	private function getIndexByPos($pos) {
81 81
 		$i = array_search($pos, $this->requiredArguments);
82
-		if(false === $i) {
82
+		if (false === $i) {
83 83
 			$i = array_search($pos, $this->optionalArguments);
84
-			if(false !== $i) {
84
+			if (false !== $i) {
85 85
 				$i += count($this->requiredArguments);
86 86
 			}
87 87
 		}
88
-		if(false === $i) {
88
+		if (false === $i) {
89 89
 			throw new Exception('argument '.$pos.' not found');
90 90
 		}
91 91
 
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 		$i = $this->getIndexByPos($pos);
102 102
 		$required = $i < count($this->requiredArguments);
103 103
 
104
-		if(false === array_key_exists($i, $this->arguments)) {
105
-			if(true === $required) {
104
+		if (false === array_key_exists($i, $this->arguments)) {
105
+			if (true === $required) {
106 106
 				throw new Exception('no argument at position '.$i.' ('.$pos.')');
107 107
 			}
108 108
 			else {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	public function getArgumentFile($pos) {
123 123
 		$i = $this->getIndexByPos($pos);
124 124
 
125
-		if(false === is_file($this->arguments[$i])) {
125
+		if (false === is_file($this->arguments[$i])) {
126 126
 			throw new Exception('argument '.$i.' is not a file');
127 127
 		}
128 128
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	public function getArgumentPrivateKey($pos) {
137 137
 		$content = Common::getPrivateKey($this->getArgumentStringOrFileContent($pos));
138 138
 		$cryptTool = CryptTool::getInstance();
139
-		if(null !== $content) {
139
+		if (null !== $content) {
140 140
 			return $cryptTool->hex2bin($content);
141 141
 		}
142 142
 		return null;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	public function getArgumentPublicKey($pos) {
150 150
 		$content = Common::getPublicKey($this->getArgumentStringOrFileContent($pos));
151 151
 		$cryptTool = CryptTool::getInstance();
152
-		if(null !== $content) {
152
+		if (null !== $content) {
153 153
 			return $cryptTool->hex2bin($content);
154 154
 		}
155 155
 		return null;
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 */
162 162
 	private function getArgumentStringOrFileContent($pos) {
163 163
 		$content = $this->getArgument($pos);
164
-		if(file_exists($content)) {
164
+		if (file_exists($content)) {
165 165
 			$content = trim(file_get_contents($content));
166 166
 		}
167 167
 		return $content;
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	public function getArgumentThreemaId($pos) {
175 175
 		$content = $this->getArgument($pos);
176
-		if(null !== $content && strlen($content) == 8) {
176
+		if (null !== $content && strlen($content) == 8) {
177 177
 			return strtoupper($content);
178 178
 		}
179 179
 		return null;
@@ -183,12 +183,12 @@  discard block
 block discarded – undo
183 183
 	 * @return string
184 184
 	 */
185 185
 	protected function readStdIn() {
186
-		$f = fopen( 'php://stdin', 'r' );
186
+		$f = fopen('php://stdin', 'r');
187 187
 
188 188
 		$lines = array();
189
-		while( $line = trim(fgets($f)) ) {
189
+		while ($line = trim(fgets($f))) {
190 190
 
191
-			if(strlen($line) == 0 || $line == "\n") {
191
+			if (strlen($line) == 0 || $line == "\n") {
192 192
 				continue;
193 193
 			}
194 194
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 
208 208
 		$argCount = null !== $this->arguments ? count($this->arguments) : 0;
209 209
 
210
-		if($argCount < count($this->requiredArguments)) {
210
+		if ($argCount < count($this->requiredArguments)) {
211 211
 			throw new Exception('invalid count of arguments');
212 212
 		}
213 213
 		$this->doRun();
@@ -220,10 +220,10 @@  discard block
 block discarded – undo
220 220
 	final public function help($shellColors = true) {
221 221
 		$args = array_merge($this->requiredArguments, $this->optionalArguments);
222 222
 
223
-		if(count($args) > 0) {
223
+		if (count($args) > 0) {
224 224
 			$colorPrefix = '';
225 225
 			$colorPostfix = '';
226
-			if(true === $shellColors) {
226
+			if (true === $shellColors) {
227 227
 				$colorPrefix = "\033[0;36m\033[40m";
228 228
 				$colorPostfix = "\033[0m";
229 229
 			}
Please login to merge, or discard this patch.
source/Threema/Console/Run.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
 	}
89 89
 
90 90
 	private function register($argumentKey, Base $command) {
91
-		if(is_scalar($argumentKey)) {
91
+		if (is_scalar($argumentKey)) {
92 92
 			$argumentKey = array($argumentKey);
93 93
 		}
94 94
 
95 95
 		//check for existing commands with the same arguments
96
-		foreach($this->commands as $commandValues) {
96
+		foreach ($this->commands as $commandValues) {
97 97
 			$ex = $commandValues[0];
98
-			if(null !== $ex && is_array($ex)) {
99
-				if(count($ex) == count($argumentKey)
98
+			if (null !== $ex && is_array($ex)) {
99
+				if (count($ex) == count($argumentKey)
100 100
 					&& count(array_diff($ex, $argumentKey)) == 0) {
101 101
 					throw new Exception('arguments '.implode($argumentKey).' already used');
102 102
 				}
@@ -115,17 +115,17 @@  discard block
 block discarded – undo
115 115
 		$argumentLength = 0;
116 116
 
117 117
 		//find the correct command by arguments and arguments count
118
-		foreach($this->commands as $data) {
119
-			if(is_scalar($data)) {
118
+		foreach ($this->commands as $data) {
119
+			if (is_scalar($data)) {
120 120
 				continue;
121 121
 			}
122 122
 
123 123
 			list($keys, $command) = $data;
124
-			if(array_slice($this->arguments, 0, count($keys)) == $keys) {
124
+			if (array_slice($this->arguments, 0, count($keys)) == $keys) {
125 125
 				$argCount = count($this->arguments)-count($keys);
126 126
 
127 127
 				/** @noinspection PhpUndefinedMethodInspection */
128
-				if($argCount >= $command->getRequiredArgumentCount()
128
+				if ($argCount >= $command->getRequiredArgumentCount()
129 129
 					&& $argCount <= $command->getAllArgumentsCount()) {
130 130
 					$found = $command;
131 131
 					$argumentLength = count($keys);
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
 			}
135 135
 		}
136 136
 
137
-		if($argumentLength > 0) {
137
+		if ($argumentLength > 0) {
138 138
 			array_splice($this->arguments, 0, $argumentLength);
139 139
 		}
140 140
 
141
-		if(null === $found) {
141
+		if (null === $found) {
142 142
 			$this->help();
143 143
 		}
144 144
 		else {
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 			try {
148 148
 				$found->run($this->arguments);
149 149
 			}
150
-			catch(Exception $x) {
150
+			catch (Exception $x) {
151 151
 				Common::l();
152 152
 				Common::e('ERROR: '.$x->getMessage());
153 153
 				Common::e(get_class($x));
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 		Common::l('CryptTool: '.$defaultCryptTool->getName().' ('.$defaultCryptTool->getDescription().')');
167 167
 		Common::l(str_repeat('.', 40));
168 168
 		Common::l();
169
-		foreach($this->commands as $data) {
170
-			if(is_scalar($data)) {
169
+		foreach ($this->commands as $data) {
170
+			if (is_scalar($data)) {
171 171
 				Common::l($data);
172 172
 				Common::l(str_repeat('-', strlen($data)));
173 173
 				Common::l();
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
 	}
185 185
 
186 186
 	public function writeHelp(\Closure $writer) {
187
-		if(null !== $writer) {
187
+		if (null !== $writer) {
188 188
 
189
-			foreach($this->commands as $data) {
190
-				if(is_scalar($data)) {
189
+			foreach ($this->commands as $data) {
190
+				if (is_scalar($data)) {
191 191
 					$writer->__invoke($data, null, null, false);
192 192
 				}
193 193
 				else {
Please login to merge, or discard this patch.
source/Threema/MsgApi/PublicKeyStores/File.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * @throws Exception if the file does not exist or not writable
26 26
 	 */
27 27
 	public function __construct($file) {
28
-		if(false === is_writable($file)) {
28
+		if (false === is_writable($file)) {
29 29
 			throw new Exception('file '.$file.' does not exist or is not writable');
30 30
 		}
31 31
 		$this->file = $file;
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function findPublicKey($threemaId) {
41 41
 		$storeHandle = fopen($this->file, 'r');
42
-		if(false === $storeHandle) {
42
+		if (false === $storeHandle) {
43 43
 			throw new Exception('could not open file '.$this->file);
44 44
 		}
45 45
 		else {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			$publicKey = null;
48 48
 			while (!feof($storeHandle)) {
49 49
 				$buffer = fgets($storeHandle, 4096);
50
-				if(substr($buffer, 0, 8) == $threemaId) {
50
+				if (substr($buffer, 0, 8) == $threemaId) {
51 51
 					$publicKey = str_replace("\n", '', substr($buffer, 8));
52 52
 					continue;
53 53
 				}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 * @return File
75 75
 	 */
76 76
 	public static function create($path) {
77
-		if(false === file_exists($path)) {
77
+		if (false === file_exists($path)) {
78 78
 			//touch
79 79
 			touch($path);
80 80
 		}
Please login to merge, or discard this patch.
source/Threema/MsgApi/Helpers/E2EHelper.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/CryptToolSodiumDep.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@
 block discarded – undo
121 121
 	 * @throws Exception
122 122
 	 */
123 123
 	public function validate() {
124
-		if(false === $this->isSupported()) {
124
+		if (false === $this->isSupported()) {
125 125
 			throw new Exception('Sodium implementation not supported');
126 126
 		}
127 127
 		return true;
Please login to merge, or discard this patch.