Adds PHP code, autogenerated from Haxe (somewhat)

We do some wizardry to avoid too much code.
This commit is contained in:
Nemo 2024-01-08 10:44:39 +05:30
parent 2bbaf6120e
commit 28d3191077
6 changed files with 100 additions and 4 deletions

9
.gitignore vendored
View File

@ -2,4 +2,11 @@ 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

View File

@ -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/*
jar -cf epicqr-release.jar build/*
# PHP
haxe php.hxml
sed -i '/^use/d' src/eci/*.php
sed -i '/^Boot::/d' src/eci/*.php

10
php.hxml Normal file
View File

@ -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

View File

@ -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);

31
src/eci/EpicQR.php Normal file
View File

@ -0,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);
}
}

30
src/eci/Result.php Normal file
View File

@ -0,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;
}
}