🏡 index : github.com/captn3m0/epicqr.git

author Nemo <me@captnemo.in> 2024-01-08 10:44:39.0 +05:30:00
committer Nemo <me@captnemo.in> 2024-01-08 10:44:39.0 +05:30:00
commit
28d3191077389bf63ecec3b69feb7ab19681b7bf [patch]
tree
05f1ffaaf02251d0e7754807ad894ff9ecc27994
parent
2bbaf6120edf9b12b0f7d21868768c64832d1ebb
download
28d3191077389bf63ecec3b69feb7ab19681b7bf.tar.gz

Adds PHP code, autogenerated from Haxe (somewhat)

We do some wizardry to avoid too much code.

Diff

 .gitignore         |  9 ++++++++-
 php.hxml           | 10 ++++++++++
 _scripts/build.sh  |  7 ++++++-
 src/eci/EpicQR.hx  | 17 +++++++++++++++++
 src/eci/EpicQR.php | 31 +++++++++++++++++++++++++++++++
 src/eci/Result.php | 30 ++++++++++++++++++++++++++++++
 6 files changed, 100 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 25a4539..a812e52 100644
--- a/.gitignore
+++ a/.gitignore
@@ -1,5 +1,12 @@
haxe-build.zip
build/

*.jar
*.class
*.class
# These are generated PHP code for Haxe
# but since our PHP code is so simple, we
# don't need any of these
src/php
src/Array_hx.php
src/Std.php
src/haxe
diff --git a/php.hxml b/php.hxml
new file mode 100644
index 0000000..e6bb4ac 100644
--- /dev/null
+++ a/php.hxml
@@ -1,0 +1,10 @@
-cp src
-w -WDeprecatedEnumAbstract
-php .
--dce full
--macro keep('eci.EpicQR')
--macro keep('eci.Result')
-D analyzer_optimize
-D real-position
-D php-lib=src
eci.EpicQR
diff --git a/_scripts/build.sh b/_scripts/build.sh
index 6849400..769c87a 100644
--- a/_scripts/build.sh
+++ a/_scripts/build.sh
@@ -5,4 +5,9 @@

# Java
javac -cp src src/eci/*.java -d build/
jar -cf epicqr-release.jar build/*
jar -cf epicqr-release.jar build/*

# PHP
haxe php.hxml
sed -i '/^use/d' src/eci/*.php
sed -i '/^Boot::/d' src/eci/*.php
diff --git a/src/eci/EpicQR.hx b/src/eci/EpicQR.hx
index 4cd164f..3be14d4 100644
--- a/src/eci/EpicQR.hx
+++ a/src/eci/EpicQR.hx
@@ -1,11 +1,17 @@
package eci;

#if php
import php.Global;
import php.Lib;
#elseif nodejs
import js.node.Crypto;
import js.node.Buffer;
#else
import haxe.io.Bytes;
import haxe.crypto.Base64;
import haxe.crypto.mode.CBC;
import haxe.Json;
import js.node.Crypto;
import js.node.Buffer;
#end

@:expose
class EpicQR{
@@ -15,7 +21,9 @@

    public static inline var IV:String  = "H76$suq23_po(8sD";
    public static inline var KEY:String = "X_4k$uq23FSwI.qT"; // KEY_PREFIX + SALT
    #if nodejs
    private static inline var UTF8:String = "utf8";
    #end

    static function decode(input : String){
        #if nodejs
@@ -30,6 +38,11 @@
        decrypted = decrypted.slice(0, decrypted.length - paddingLength);

        var _d = haxe.Json.parse(decrypted.toString(UTF8));
        #elseif php
        var ct = Global.base64_decode(input);
        var jsonString = Global.call_user_func('openssl_decrypt', ct, 'aes-128-cbc', KEY, 1, IV);
        var _d = Global.json_decode(jsonString);

        #else
        var cipherText:Bytes = Base64.decode(input);
        
diff --git a/src/eci/EpicQR.php b/src/eci/EpicQR.php
new file mode 100644
index 0000000..dd05ade 100644
--- /dev/null
+++ a/src/eci/EpicQR.php
@@ -1,0 +1,31 @@
<?php
/**
 * Generated by Haxe 4.3.3
 */

namespace eci;


class EpicQR {
	/**
	 * @var string
	 */
	const IV = "H76\$suq23_po(8sD";
	/**
	 * @var string
	 */
	const KEY = "X_4k\$uq23FSwI.qT";

	/**
	 * @param string $input
	 * 
	 * @return Result
	 */
	public static function decode ($input) {
		$ct = \base64_decode($input);
		$jsonString = \call_user_func("openssl_decrypt", $ct, "aes-128-cbc", "X_4k\$uq23FSwI.qT", 1, "H76\$suq23_po(8sD");
		$_d = \json_decode($jsonString);
		return new Result($_d->epic_no, $_d->unique_generated_id);
	}
}

diff --git a/src/eci/Result.php b/src/eci/Result.php
new file mode 100644
index 0000000..2f1b893 100644
--- /dev/null
+++ a/src/eci/Result.php
@@ -1,0 +1,30 @@
<?php
/**
 * Generated by Haxe 4.3.3
 */

namespace eci;


class Result {
	/**
	 * @var string
	 */
	public $epic;
	/**
	 * @var int
	 */
	public $id;

	/**
	 * @param string $epic
	 * @param int $id
	 * 
	 * @return void
	 */
	public function __construct ($epic, $id) {
		$this->epic = $epic;
		$this->id = $id;
	}
}