fix return for nodejs

This commit is contained in:
Nemo 2024-01-07 23:07:04 +05:30
parent ff481c84e2
commit d4721413ee
2 changed files with 12 additions and 9 deletions

View File

@ -16,14 +16,12 @@ 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
private static inline var UTF8:String = "utf8";
private static inline var BASE64:String = "base64";
private static inline var NODEJS_CIPHER:String = "aes-128-cbc";
static function decode(input : String){
#if nodejs
var c = Crypto.createDecipheriv(NODEJS_CIPHER, Buffer.from(KEY, UTF8), Buffer.from(IV, UTF8));
var c = Crypto.createDecipheriv("aes-128-cbc", Buffer.from(KEY, UTF8), Buffer.from(IV, UTF8));
c.setAutoPadding(false);
var decrypted = c.update(Buffer.from(input, BASE64));
var decrypted = c.update(Buffer.from(input, "base64"));
var f = c.finalContents();
decrypted = Buffer.concat([decrypted, f]);
@ -31,7 +29,7 @@ class EpicQR{
var paddingLength = decrypted[decrypted.length - 1];
decrypted = decrypted.slice(0, decrypted.length - paddingLength);
return decrypted.toString(UTF8);
var _d = haxe.Json.parse(decrypted.toString(UTF8));
#else
var cipherText:Bytes = Base64.decode(input);
@ -42,7 +40,7 @@ class EpicQR{
var jsonString = c.decrypt(CBC,cipherText).toString();
var _d = Json.parse(jsonString);
return new Result(_d.epic_no, _d.unique_generated_id);
#end
return new Result(_d.epic_no, _d.unique_generated_id);
}
}

View File

@ -10,10 +10,17 @@ class eci_EpicQR {
decrypted = js_node_buffer_Buffer.concat([decrypted,f]);
let paddingLength = decrypted[decrypted.length - 1];
decrypted = decrypted.slice(0,decrypted.length - paddingLength);
return decrypted.toString("utf8");
let _d = JSON.parse(decrypted.toString("utf8"));
return new eci_Result(_d.epic_no,_d.unique_generated_id);
}
}
$hx_exports["eci"]["EpicQR"] = eci_EpicQR;
class eci_Result {
constructor(epic,id) {
this.epic = epic;
this.id = id;
}
}
class haxe_iterators_ArrayIterator {
constructor(array) {
this.current = 0;
@ -33,6 +40,4 @@ var js_node_buffer_Buffer = require("buffer").Buffer;
eci_EpicQR.IV = "H76$suq23_po(8sD";
eci_EpicQR.KEY = "X_4k$uq23FSwI.qT";
eci_EpicQR.UTF8 = "utf8";
eci_EpicQR.BASE64 = "base64";
eci_EpicQR.NODEJS_CIPHER = "aes-128-cbc";
})(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this, {});