From 28d3191077389bf63ecec3b69feb7ab19681b7bf Mon Sep 17 00:00:00 2001 From: Nemo Date: Mon, 8 Jan 2024 10:44:39 +0530 Subject: [PATCH] Adds PHP code, autogenerated from Haxe (somewhat) We do some wizardry to avoid too much code. --- .gitignore | 9 ++++++++- _scripts/build.sh | 7 ++++++- php.hxml | 10 ++++++++++ src/eci/EpicQR.hx | 17 +++++++++++++++-- src/eci/EpicQR.php | 31 +++++++++++++++++++++++++++++++ src/eci/Result.php | 30 ++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 php.hxml create mode 100644 src/eci/EpicQR.php create mode 100644 src/eci/Result.php diff --git a/.gitignore b/.gitignore index 25a4539..a812e52 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,11 @@ haxe-build.zip build/ *.jar -*.class \ No newline at end of file +*.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 \ No newline at end of file diff --git a/_scripts/build.sh b/_scripts/build.sh index 6849400..769c87a 100644 --- a/_scripts/build.sh +++ b/_scripts/build.sh @@ -5,4 +5,9 @@ zip -r haxe-build.zip src LICENSE *.md *.json *.hxml # Java javac -cp src src/eci/*.java -d build/ -jar -cf epicqr-release.jar build/* \ No newline at end of file +jar -cf epicqr-release.jar build/* + +# PHP +haxe php.hxml +sed -i '/^use/d' src/eci/*.php +sed -i '/^Boot::/d' src/eci/*.php \ No newline at end of file diff --git a/php.hxml b/php.hxml new file mode 100644 index 0000000..e6bb4ac --- /dev/null +++ b/php.hxml @@ -0,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 \ No newline at end of file diff --git a/src/eci/EpicQR.hx b/src/eci/EpicQR.hx index 4cd164f..3be14d4 100644 --- a/src/eci/EpicQR.hx +++ b/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 @@ class EpicQR{ 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 @@ class EpicQR{ 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 --- /dev/null +++ b/src/eci/EpicQR.php @@ -0,0 +1,31 @@ +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 --- /dev/null +++ b/src/eci/Result.php @@ -0,0 +1,30 @@ +epic = $epic; + $this->id = $id; + } +} +