Completed
Pull Request — master (#28)
by rugk
02:50
created
source/Threema/MsgApi/Tools/EncryptResult.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Tools;
Please login to merge, or discard this patch.
source/Threema/MsgApi/Tools/FileAnalysisResult.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author Threema GmbH
4
- * @copyright Copyright (c) 2015 Threema GmbH
5
- */
3
+	 * @author Threema GmbH
4
+	 * @copyright Copyright (c) 2015 Threema GmbH
5
+	 */
6 6
 
7 7
 
8 8
 namespace Threema\MsgApi\Tools;
Please login to merge, or discard this patch.
samples/web/include/GetPost.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author rugk
4
- * @copyright Copyright (c) 2015 rugk
5
- * @license MIT
6
- */
3
+	 * @author rugk
4
+	 * @copyright Copyright (c) 2015 rugk
5
+	 * @license MIT
6
+	 */
7 7
 
8 8
 /**
9 9
  * Returns the parameter from GET (preferred) or POST.
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
  */
14 14
 function ReturnGetPost($name)
15 15
 {
16
-    if (isset($_GET[$name])) {
17
-        return $_GET[$name];
18
-    }
19
-    if (isset($_POST[$name])) {
20
-        return $_POST[$name];
21
-    }
16
+	if (isset($_GET[$name])) {
17
+		return $_GET[$name];
18
+	}
19
+	if (isset($_POST[$name])) {
20
+		return $_POST[$name];
21
+	}
22 22
 
23
-    return null;
23
+	return null;
24 24
 }
Please login to merge, or discard this patch.
samples/web/include/GlobalConstants.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author rugk
4
- * @copyright Copyright (c) 2015 rugk
5
- * @license MIT
6
- */
3
+	 * @author rugk
4
+	 * @copyright Copyright (c) 2015 rugk
5
+	 * @license MIT
6
+	 */
7 7
 
8 8
 /* CONSTANTS */
9 9
 const FILENAME_CONNCRED = 'ConnectionCredentials.php';
Please login to merge, or discard this patch.
samples/web/SendTextMessage.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
  */
39 39
 function SendMessage($connector, $threemaId, $message)
40 40
 {
41
-    $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector);
42
-    $result = $e2eHelper->sendTextMessage($threemaId, $message);
41
+	$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector);
42
+	$result = $e2eHelper->sendTextMessage($threemaId, $message);
43 43
 
44
-    if (true === $result->isSuccess()) {
45
-        return $result->getMessageId();
46
-    } else {
47
-        throw new Exception($result->getErrorMessage());
48
-    }
44
+	if (true === $result->isSuccess()) {
45
+		return $result->getMessageId();
46
+	} else {
47
+		throw new Exception($result->getErrorMessage());
48
+	}
49 49
 }
50 50
 
51 51
 //get params
52 52
 if (ReturnGetPost('recieverid') &&
53
-    preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid'))
53
+	preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid'))
54 54
 ) {
55
-    $threemaId = htmlentities(ReturnGetPost('recieverid'));
56
-    $message = ReturnGetPost('message');
55
+	$threemaId = htmlentities(ReturnGetPost('recieverid'));
56
+	$message = ReturnGetPost('message');
57 57
 }
58 58
 
59 59
 //create connection
@@ -61,24 +61,24 @@  discard block
 block discarded – undo
61 61
 
62 62
 //Send message
63 63
 if ($threemaId != null && $message != null) {
64
-    if (!$isIncluded) {
65
-        header('Content-Type: text/plain');
66
-    }
67
-    $actionDone = true;
64
+	if (!$isIncluded) {
65
+		header('Content-Type: text/plain');
66
+	}
67
+	$actionDone = true;
68 68
 
69
-    try {
70
-        $messageId = SendMessage($connector, $threemaId, $message);
71
-    } catch (Exception $e) {
72
-        http_response_code(500);
73
-        $errorMessage = $e->getMessage();
74
-    }
69
+	try {
70
+		$messageId = SendMessage($connector, $threemaId, $message);
71
+	} catch (Exception $e) {
72
+		http_response_code(500);
73
+		$errorMessage = $e->getMessage();
74
+	}
75 75
 }
76 76
 
77 77
 //Show direct output if the file is called directly
78 78
 if (!$isIncluded) {
79
-    if ($errorMessage == null) {
80
-        echo 'Message ID: ' . $messageId;
81
-    } else {
82
-        echo $errorMessage;
83
-    }
79
+	if ($errorMessage == null) {
80
+		echo 'Message ID: ' . $messageId;
81
+	} else {
82
+		echo $errorMessage;
83
+	}
84 84
 }
Please login to merge, or discard this patch.
samples/web/FetchPublicKey.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author rugk
4
- * @copyright Copyright (c) 2015 rugk
5
- * @license MIT
6
- */
3
+	 * @author rugk
4
+	 * @copyright Copyright (c) 2015 rugk
5
+	 * @license MIT
6
+	 */
7 7
 
8 8
 header('Content-Type: text/plain');
9 9
 
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
  */
33 33
 function FetchPublicKey($connector, $threemaId)
34 34
 {
35
-    $result = $connector->fetchPublicKey($threemaId);
36
-    if ($result->isSuccess()) {
37
-    	return $result->getPublicKey();
38
-    } else {
39
-    	throw new Exception($result->getErrorMessage());
40
-    }
35
+	$result = $connector->fetchPublicKey($threemaId);
36
+	if ($result->isSuccess()) {
37
+		return $result->getPublicKey();
38
+	} else {
39
+		throw new Exception($result->getErrorMessage());
40
+	}
41 41
 }
42 42
 
43 43
 //get params
44 44
 $threemaId = null;
45 45
 if (ReturnGetPost('threemaid') &&
46
-    preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('threemaid'))
46
+	preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('threemaid'))
47 47
 ) {
48
-    $threemaId = htmlentities(ReturnGetPost('threemaid'));
48
+	$threemaId = htmlentities(ReturnGetPost('threemaid'));
49 49
 }
50 50
 
51 51
 //create connection
@@ -53,14 +53,14 @@  discard block
 block discarded – undo
53 53
 
54 54
 //Fetch public key and return a 500 error in case of a failure
55 55
 if ($threemaId != null) {
56
-    try {
57
-        $publicKey = FetchPublicKey($connector, $threemaId);
58
-        echo $publicKey;
59
-    } catch (Exception $e) {
60
-        http_response_code(500);
61
-        echo $e->getMessage();
62
-    }
56
+	try {
57
+		$publicKey = FetchPublicKey($connector, $threemaId);
58
+		echo $publicKey;
59
+	} catch (Exception $e) {
60
+		http_response_code(500);
61
+		echo $e->getMessage();
62
+	}
63 63
 } else {
64
-    http_response_code(500);
65
-    echo 'Invalid Threema ID';
64
+	http_response_code(500);
65
+	echo 'Invalid Threema ID';
66 66
 }
Please login to merge, or discard this patch.
samples/web/SendE2EText.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author rugk
4
- * @copyright Copyright (c) 2015 rugk
5
- * @license MIT
6
- */
3
+	 * @author rugk
4
+	 * @copyright Copyright (c) 2015 rugk
5
+	 * @license MIT
6
+	 */
7 7
 
8 8
 header('Content-Type: text/plain');
9 9
 
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function SendText($connector, $receiverId, $message)
33 33
 {
34
-    //get private key
35
-    $privateKey = KeyHexToBin(MSGAPI_PRIVATE_KEY);
36
-
37
-    //send message
38
-    $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($privateKey, $connector);
39
-    $result = $e2eHelper->sendTextMessage($receiverId, $message);
40
-
41
-    //show result
42
-    if (true === $result->isSuccess()) {
43
-    	echo 'Message ID: '.$result->getMessageId() . "\n";
44
-    } else {
45
-    	echo 'Error: '.$result->getErrorMessage() . "\n";
46
-    }
34
+	//get private key
35
+	$privateKey = KeyHexToBin(MSGAPI_PRIVATE_KEY);
36
+
37
+	//send message
38
+	$e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper($privateKey, $connector);
39
+	$result = $e2eHelper->sendTextMessage($receiverId, $message);
40
+
41
+	//show result
42
+	if (true === $result->isSuccess()) {
43
+		echo 'Message ID: '.$result->getMessageId() . "\n";
44
+	} else {
45
+		echo 'Error: '.$result->getErrorMessage() . "\n";
46
+	}
47 47
 
48 48
 }
49 49
 
Please login to merge, or discard this patch.
samples/web/include/Connection.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * @author rugk
4
- * @copyright Copyright (c) 2015 rugk
5
- * @license MIT
6
- */
3
+	 * @author rugk
4
+	 * @copyright Copyright (c) 2015 rugk
5
+	 * @license MIT
6
+	 */
7 7
 
8 8
 use Threema\MsgApi\Connection;
9 9
 use Threema\MsgApi\ConnectionSettings;
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
  */
21 21
 function CreateConnection($keystorePath='../../keystore.php', $useTlsOptions=true)
22 22
 {
23
-    $publicKeyStore = CreatePublicKeyStore($keystorePath);
24
-    $settings = CreateConnectionSettings($useTlsOptions);
25
-    $connector = InitiateConnection($settings, $publicKeyStore);
23
+	$publicKeyStore = CreatePublicKeyStore($keystorePath);
24
+	$settings = CreateConnectionSettings($useTlsOptions);
25
+	$connector = InitiateConnection($settings, $publicKeyStore);
26 26
 
27
-    return $connector;
27
+	return $connector;
28 28
 }
29 29
 
30 30
 /**
@@ -36,12 +36,12 @@  discard block
 block discarded – undo
36 36
  */
37 37
 function CreatePublicKeyStore($keystorePath)
38 38
 {
39
-    if (!file_exists($keystorePath)) {
40
-        if (!touch($keystorePath)) {
41
-            throw new Exception("PHP keystore could not be created.");
42
-        }
43
-    }
44
-    return new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath);
39
+	if (!file_exists($keystorePath)) {
40
+		if (!touch($keystorePath)) {
41
+			throw new Exception("PHP keystore could not be created.");
42
+		}
43
+	}
44
+	return new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath);
45 45
 }
46 46
 
47 47
 /**
@@ -53,27 +53,27 @@  discard block
 block discarded – undo
53 53
  */
54 54
 function CreateConnectionSettings($useTlsOptions)
55 55
 {
56
-    if ($useTlsOptions == true) {
57
-        //create a connection with advanced options
58
-        $settings = new ConnectionSettings(
59
-            MSGAPI_GATEWAY_THREEMA_ID,
60
-            MSGAPI_GATEWAY_THREEMA_ID_SECRET,
61
-            null,
62
-            [
63
-                'forceHttps' => true,
64
-                'tlsVersion' => '1.2',
65
-                'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256'
66
-            ]
67
-        );
68
-    } else {
69
-        //create a connection with default options
70
-        $settings = new ConnectionSettings(
71
-            MSGAPI_GATEWAY_THREEMA_ID,
72
-            MSGAPI_GATEWAY_THREEMA_ID_SECRET
73
-        );
74
-    }
56
+	if ($useTlsOptions == true) {
57
+		//create a connection with advanced options
58
+		$settings = new ConnectionSettings(
59
+			MSGAPI_GATEWAY_THREEMA_ID,
60
+			MSGAPI_GATEWAY_THREEMA_ID_SECRET,
61
+			null,
62
+			[
63
+				'forceHttps' => true,
64
+				'tlsVersion' => '1.2',
65
+				'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256'
66
+			]
67
+		);
68
+	} else {
69
+		//create a connection with default options
70
+		$settings = new ConnectionSettings(
71
+			MSGAPI_GATEWAY_THREEMA_ID,
72
+			MSGAPI_GATEWAY_THREEMA_ID_SECRET
73
+		);
74
+	}
75 75
 
76
-    return $settings;
76
+	return $settings;
77 77
 }
78 78
 
79 79
 /**
@@ -86,5 +86,5 @@  discard block
 block discarded – undo
86 86
  */
87 87
 function InitiateConnection($settings, $publicKeyStore)
88 88
 {
89
-    return new Connection($settings, $publicKeyStore);
89
+	return new Connection($settings, $publicKeyStore);
90 90
 }
Please login to merge, or discard this patch.
samples/web/include/PublicKey.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function KeyCheck($publicKey, $suffix = '')
16 16
 {
17
-    // RegExp: https://regex101.com/r/sU5tC8/1
18
-    return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey);
17
+	// RegExp: https://regex101.com/r/sU5tC8/1
18
+	return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey);
19 19
 }
20 20
 
21 21
 /**
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
  */
33 33
 function KeyGetUserDisplay($publicKey)
34 34
 {
35
-    //force key to be binary
36
-    if (ctype_alnum($publicKey)) {
37
-        $publicKey = KeyHexToBin($publicKey);
38
-    }
35
+	//force key to be binary
36
+	if (ctype_alnum($publicKey)) {
37
+		$publicKey = KeyHexToBin($publicKey);
38
+	}
39 39
 
40
-    //create short hash
41
-    $shortHash = substr(hash('sha256', $publicKey, 0, 32));
42
-    return $shortHash;
40
+	//create short hash
41
+	$shortHash = substr(hash('sha256', $publicKey, 0, 32));
42
+	return $shortHash;
43 43
 }
44 44
 
45 45
 /**
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
  */
52 52
 function KeyHexToBin($keyHex)
53 53
 {
54
-    //delete prefix
55
-    $keyTypeCheck = substr($keyHex, 0, 8);
56
-    if ($keyTypeCheck == 'private:' || $keyTypeCheck == 'public:') {
57
-        $keyHex = substr($keyHex, 8);
58
-    }
54
+	//delete prefix
55
+	$keyTypeCheck = substr($keyHex, 0, 8);
56
+	if ($keyTypeCheck == 'private:' || $keyTypeCheck == 'public:') {
57
+		$keyHex = substr($keyHex, 8);
58
+	}
59 59
 
60
-    //convert key
61
-    $keyBin = hex2bin($keyHex);
62
-    return $keyBin;
60
+	//convert key
61
+	$keyBin = hex2bin($keyHex);
62
+	return $keyBin;
63 63
 }
Please login to merge, or discard this patch.