Skip to content

Commit

Permalink
Update to 1.1.3
Browse files Browse the repository at this point in the history
downloaded 2015-11-09
  • Loading branch information
rugk committed Nov 9, 2015
1 parent 0f35deb commit ac05f74
Show file tree
Hide file tree
Showing 180 changed files with 5,353 additions and 5,226 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# msgapi-sdk-php
Version: 1.1.0
Version: 1.1.3

## Installation
- Install PHP 5.4 or later: [https://secure.php.net/manual/en/install.php](https://secure.php.net/manual/en/install.php)
Expand Down
60 changes: 30 additions & 30 deletions docs/classes/Curve25519.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/FieldElement.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Poly1305.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Salsa20.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Salt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/SaltException.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.Base.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.Capability.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.Credits.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.Decrypt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.DerivePublicKey.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.Encrypt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.GenerateKeyPair.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.HashEmail.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.HashPhone.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.LookupIdByEmail.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.LookupIdByPhoneNo.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.LookupPublicKeyById.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.ReceiveMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.SendE2EFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.SendE2EImage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.SendE2EText.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Command.SendSimple.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Common.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Console.Run.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Core.AssocArray.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Core.Exception.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Core.KeyPair.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.Core.Url.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Capability.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.CommandInterface.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Credits.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.DownloadFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.FetchPublicKey.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.LookupEmail.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.LookupPhone.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.MultiPartCommandInterface.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.CapabilityResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.CreditsResult.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.LookupIdResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.Result.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.SendE2EResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.SendSimpleResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.Results.UploadFileResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.SendE2E.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.SendSimple.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Commands.UploadFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Connection.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.ConnectionSettings.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Constants.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Exceptions.BadMessageException.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

130 changes: 97 additions & 33 deletions docs/classes/Threema.MsgApi.Helpers.E2EHelper.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Helpers.ReceiveMessageResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Messages.DeliveryReceipt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Messages.FileMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Messages.ImageMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Messages.TextMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Messages.ThreemaMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.PublicKeyStore.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.PublicKeyStores.File.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.PublicKeyStores.PhpFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Receiver.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tests.CommonTests.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tests.Constants.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tests.CryptToolTests.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.CryptTool.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.CryptToolSalt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.CryptToolSodium.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.CryptToolSodiumDep.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.EncryptResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.FileAnalysisResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/Threema.MsgApi.Tools.FileAnalysisTool.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.Curve25519.Curve25519.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.FieldElement.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.Poly1305.Poly1305.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.Salsa20.Salsa20.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.Salt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.SaltException.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Salt.autoload.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.Base.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.Capability.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.Credits.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.Decrypt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.DerivePublicKey.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.Encrypt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.GenerateKeyPair.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.HashEmail.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.HashPhone.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.LookupIdByEmail.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.LookupIdByPhoneNo.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.LookupPublicKeyById.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.ReceiveMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.SendE2EFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.SendE2EImage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.SendE2EText.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Command.SendSimple.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Common.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Console.Run.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Core.AssocArray.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Core.Exception.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Core.KeyPair.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.Core.Url.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Capability.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.CommandInterface.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Credits.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.DownloadFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.FetchPublicKey.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.LookupEmail.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.LookupPhone.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.MultiPartCommandInterface.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.CapabilityResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.CreditsResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.DownloadFileResult.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.LookupIdResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.Result.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.SendE2EResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.SendSimpleResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.Results.UploadFileResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.SendE2E.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.SendSimple.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Commands.UploadFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Connection.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.ConnectionSettings.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Constants.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Exceptions.BadMessageException.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Exceptions.DecryptionFailedException.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Exceptions.InvalidArgumentException.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Helpers.E2EHelper.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Helpers.ReceiveMessageResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Messages.DeliveryReceipt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Messages.FileMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Messages.ImageMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Messages.TextMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Messages.ThreemaMessage.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.PublicKeyStore.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.PublicKeyStores.File.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.PublicKeyStores.PhpFile.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Receiver.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tests.CommonTests.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tests.Constants.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tests.CryptToolTest.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.CryptTool.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.CryptToolSalt.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.CryptToolSodium.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.CryptToolSodiumDep.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.EncryptResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.FileAnalysisResult.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/files/Threema.MsgApi.Tools.FileAnalysisTool.html

Large diffs are not rendered by default.

107 changes: 68 additions & 39 deletions docs/files/Threema/MsgApi/Helpers/E2EHelper.php.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Threema\MsgApi\Commands\Results\CapabilityResult;
use Threema\MsgApi\Connection;
use Threema\MsgApi\Messages\FileMessage;
use Threema\MsgApi\Messages\ImageMessage;
use Threema\MsgApi\Messages\ThreemaMessage;
use Threema\MsgApi\Tools\CryptTool;
use Threema\Core\Exception;
use Threema\MsgApi\Tools\FileAnalysisTool;
Expand Down Expand Up @@ -178,6 +179,7 @@ class E2EHelper {
return $this->connection->sendE2E($threemaId, $nonce, $fileMessage);
}


/**
* Encrypt a message and download the files of the message to the $outputFolder
*
Expand All @@ -186,10 +188,19 @@ class E2EHelper {
* @param string $box box as binary string
* @param string $nonce nonce as binary string
* @param string|null $outputFolder folder for storing the files
* @throws \Threema\Core\Exception
* @param \Closure $downloadMessage
* @return ReceiveMessageResult
* @throws Exception
* @throws \Threema\MsgApi\Exceptions\BadMessageException
* @throws \Threema\MsgApi\Exceptions\DecryptionFailedException
* @throws \Threema\MsgApi\Exceptions\UnsupportedMessageTypeException
*/
public final function receiveMessage($threemaId, $messageId, $box, $nonce, $outputFolder = null) {
public final function receiveMessage($threemaId,
$messageId,
$box,
$nonce,
$outputFolder = null,
\Closure $downloadMessage = null) {

if($outputFolder == null || strlen($outputFolder) == 0) {
$outputFolder = '.';
Expand All @@ -216,51 +227,48 @@ class E2EHelper {
$receiveResult = new ReceiveMessageResult($messageId, $message);

if($message instanceof ImageMessage) {
$result = $this->connection->downloadFile($message->getBlobId());
if(null === $result || false === $result->isSuccess()) {
throw new Exception('could not download the image with blob id '.$message->getBlobId());
}

$image = $this->cryptTool->decryptImage(
$result->getData(),
hex2bin($receiverPublicKey->getPublicKey()),
$this->privateKey,
$message->getNonce()
);
$result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage);
if(null !== $result && true === $result->isSuccess()) {
$image = $this->cryptTool->decryptImage(
$result->getData(),
hex2bin($receiverPublicKey->getPublicKey()),
$this->privateKey,
$message->getNonce()
);

if (null === $image) {
throw new Exception('decryption of image failed');
}
//save file
$filePath = $outputFolder . '/' . $messageId . '.jpg';
$f = fopen($filePath, 'w+');
fwrite($f, $image);
fclose($f);

if(null === $image) {
throw new Exception('decryption of image failed');
$receiveResult->addFile('image', $filePath);
}
//save file
$filePath = $outputFolder.'/'.$messageId.'.jpg';
$f = fopen($filePath, 'w+');
fwrite($f, $image);
fclose($f);

$receiveResult->addFile('image', $filePath);
}
else if($message instanceof FileMessage) {
$result = $this->connection->downloadFile($message->getBlobId());
if(null === $result || false === $result->isSuccess()) {
throw new Exception('could not download the file with blob id '.$message->getBlobId());
}
$result = $this->downloadFile($message, $message->getBlobId(), $downloadMessage);

$file = $this->cryptTool->decryptFile(
$result->getData(),
hex2bin($message->getEncryptionKey()));
if(null !== $result && true === $result->isSuccess()) {
$file = $this->cryptTool->decryptFile(
$result->getData(),
hex2bin($message->getEncryptionKey()));

if(null === $file) {
throw new Exception('file decryption failed');
}
if (null === $file) {
throw new Exception('file decryption failed');
}

//save file
$filePath = $outputFolder.'/'.$messageId.'-'.$message->getFilename();
file_put_contents($filePath, $file);
//save file
$filePath = $outputFolder . '/' . $messageId . '-' . $message->getFilename();
file_put_contents($filePath, $file);

$receiveResult->addFile('file', $filePath);
$receiveResult->addFile('file', $filePath);
}

if(null !== $message->getThumbnailBlobId() && strlen($message->getThumbnailBlobId()) > 0) {
$result = $this->connection->downloadFile($message->getThumbnailBlobId());
$result = $this->downloadFile($message, $message->getThumbnailBlobId(), $downloadMessage);
if(null !== $result && true === $result->isSuccess()) {
$file = $this->cryptTool->decryptFileThumbnail(
$result->getData(),
Expand All @@ -285,9 +293,9 @@ class E2EHelper {
* Fetch a public key and check the capability of the threemaId
*
* @param string $threemaId
* @param callable $capabilityCheck
* @param \Closure $capabilityCheck
* @return string Public key as binary
* @throws \Threema\Core\Exception
* @throws Exception
*/
private final function fetchPublicKeyAndCheckCapability($threemaId, \Closure $capabilityCheck = null) {
//fetch the public key
Expand All @@ -307,5 +315,26 @@ class E2EHelper {

return hex2bin($receiverPublicKey->getPublicKey());
}

/**
* @param ThreemaMessage $message
* @param string $blobId blob id as hex
* @param \Closure|null $downloadMessage
* @return null|\Threema\MsgApi\Commands\Results\DownloadFileResult
* @throws Exception
*/
private final function downloadFile(ThreemaMessage $message, $blobId, \Closure $downloadMessage = null) {
if(null === $downloadMessage
|| true === $downloadMessage->__invoke($message, $blobId)) {
//make a download
$result = $this->connection->downloadFile($blobId);
if(null === $result || false === $result->isSuccess()) {
throw new Exception('could not download the file with blob id '.$blobId);
}

return $result;
}
return null;
}
}

Loading

0 comments on commit ac05f74

Please sign in to comment.