@@ -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 | } |
@@ -104,14 +104,14 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | final public function encryptMessageText($text, $senderPrivateKey, $recipientPublicKey, $nonce) { |
| 106 | 106 | /* prepend type byte (0x01) to message data */ |
| 107 | - $textBytes = "\x01" . $text; |
|
| 107 | + $textBytes = "\x01".$text; |
|
| 108 | 108 | |
| 109 | 109 | /* determine random amount of PKCS7 padding */ |
| 110 | 110 | $padbytes = mt_rand(1, 255); |
| 111 | 111 | |
| 112 | 112 | /* append padding */ |
| 113 | 113 | $padbytes = 0; |
| 114 | - while($padbytes < 1 || $padbytes > 255) { |
|
| 114 | + while ($padbytes < 1 || $padbytes > 255) { |
|
| 115 | 115 | $padbytes = ord($this->createRandom(1)); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $senderPrivateKey, |
| 133 | 133 | $recipientPublicKey, |
| 134 | 134 | $nonce) { |
| 135 | - $message = "\x02" . hex2bin($uploadFileResult->getBlobId()); |
|
| 135 | + $message = "\x02".hex2bin($uploadFileResult->getBlobId()); |
|
| 136 | 136 | $message .= pack('V', $encryptResult->getSize()); |
| 137 | 137 | $message .= $encryptResult->getNonce(); |
| 138 | 138 | |
@@ -163,11 +163,11 @@ discard block |
||
| 163 | 163 | 'i' => 0 |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | - if($thumbnailUploadFileResult != null && strlen($thumbnailUploadFileResult->getBlobId()) > 0) { |
|
| 166 | + if ($thumbnailUploadFileResult != null && strlen($thumbnailUploadFileResult->getBlobId()) > 0) { |
|
| 167 | 167 | $messageContent['t'] = $thumbnailUploadFileResult->getBlobId(); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $message = "\x17" . json_encode($messageContent); |
|
| 170 | + $message = "\x17".json_encode($messageContent); |
|
| 171 | 171 | |
| 172 | 172 | /* determine random amount of PKCS7 padding */ |
| 173 | 173 | $padbytes = mt_rand(1, 255); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | /* remove padding */ |
| 242 | 242 | $padbytes = ord($data[strlen($data)-1]); |
| 243 | - $realDataLength = strlen($data) - $padbytes; |
|
| 243 | + $realDataLength = strlen($data)-$padbytes; |
|
| 244 | 244 | if ($realDataLength < 1) { |
| 245 | 245 | throw new BadMessageException(); |
| 246 | 246 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | return new TextMessage(substr($data, 1)); |
| 267 | 267 | case DeliveryReceipt::TYPE_CODE: |
| 268 | 268 | /* Delivery receipt */ |
| 269 | - if ($realDataLength < (self::MESSAGE_ID_LEN-2) || (($realDataLength - 2) % self::MESSAGE_ID_LEN) != 0) { |
|
| 269 | + if ($realDataLength < (self::MESSAGE_ID_LEN-2) || (($realDataLength-2)%self::MESSAGE_ID_LEN) != 0) { |
|
| 270 | 270 | throw new BadMessageException(); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | return new DeliveryReceipt($receiptType, $messageIds); |
| 277 | 277 | case ImageMessage::TYPE_CODE: |
| 278 | 278 | /* Image Message */ |
| 279 | - if ($realDataLength != 1 + self::BLOB_ID_LEN + self::IMAGE_FILE_SIZE_LEN + self::IMAGE_NONCE_LEN) { |
|
| 279 | + if ($realDataLength != 1+self::BLOB_ID_LEN+self::IMAGE_FILE_SIZE_LEN+self::IMAGE_NONCE_LEN) { |
|
| 280 | 280 | throw new BadMessageException(); |
| 281 | 281 | } |
| 282 | 282 | |
@@ -287,12 +287,12 @@ discard block |
||
| 287 | 287 | case FileMessage::TYPE_CODE: |
| 288 | 288 | /* Image Message */ |
| 289 | 289 | $decodeResult = json_decode(substr($data, 1), true); |
| 290 | - if(null === $decodeResult || false === $decodeResult) { |
|
| 290 | + if (null === $decodeResult || false === $decodeResult) { |
|
| 291 | 291 | throw new BadMessageException(); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $values = AssocArray::byJsonString(substr($data, 1), array('b', 't', 'k', 'm', 'n', 's')); |
| 295 | - if(null === $values) { |
|
| 295 | + if (null === $values) { |
|
| 296 | 296 | throw new BadMessageException(); |
| 297 | 297 | } |
| 298 | 298 | |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | * @return null|string |
| 395 | 395 | */ |
| 396 | 396 | public final function decryptFile($data, $key) { |
| 397 | - $result = $this->openSecretBox($data, self::FILE_NONCE, $key); |
|
| 397 | + $result = $this->openSecretBox($data, self::FILE_NONCE, $key); |
|
| 398 | 398 | return false === $result ? null : $result; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -405,7 +405,7 @@ discard block |
||
| 405 | 405 | */ |
| 406 | 406 | public final function encryptFileThumbnail($data, $key) { |
| 407 | 407 | $box = $this->makeSecretBox($data, self::FILE_THUMBNAIL_NONCE, $key); |
| 408 | - return new EncryptResult($box, $key, self::FILE_THUMBNAIL_NONCE, strlen($box)); |
|
| 408 | + return new EncryptResult($box, $key, self::FILE_THUMBNAIL_NONCE, strlen($box)); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | public final function decryptFileThumbnail($data, $key) { |