mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
incorporate ArrayBuffer base Dish type. Add global file shim to node index. Fix Buffer -> ArrayBuffer transformation
This commit is contained in:
parent
e4ee0fc397
commit
af504891e4
6 changed files with 13 additions and 17 deletions
|
@ -387,7 +387,7 @@ class Dish {
|
||||||
[Dish.BIG_NUMBER]: () => Promise.resolve(DishBigNumber.toArrayBuffer.bind(this)()),
|
[Dish.BIG_NUMBER]: () => Promise.resolve(DishBigNumber.toArrayBuffer.bind(this)()),
|
||||||
[Dish.JSON]: () => Promise.resolve(DishJSON.toArrayBuffer.bind(this)()),
|
[Dish.JSON]: () => Promise.resolve(DishJSON.toArrayBuffer.bind(this)()),
|
||||||
[Dish.FILE]: () => DishFile.toArrayBuffer.bind(this)(),
|
[Dish.FILE]: () => DishFile.toArrayBuffer.bind(this)(),
|
||||||
[Dish.LIST_FILE]: () => DishListFile.toArrayBuffer.bind(this)(),
|
[Dish.LIST_FILE]: () => Promise.resolve(DishListFile.toArrayBuffer.bind(this)()),
|
||||||
[Dish.BYTE_ARRAY]: () => Promise.resolve(DishByteArray.toArrayBuffer.bind(this)()),
|
[Dish.BYTE_ARRAY]: () => Promise.resolve(DishByteArray.toArrayBuffer.bind(this)()),
|
||||||
},
|
},
|
||||||
node: {
|
node: {
|
||||||
|
|
|
@ -94,7 +94,7 @@ class Utils {
|
||||||
const paddedBytes = new Array(numBytes);
|
const paddedBytes = new Array(numBytes);
|
||||||
paddedBytes.fill(padByte);
|
paddedBytes.fill(padByte);
|
||||||
|
|
||||||
Array.prototype.map.call(arr, function(b, i) {
|
[...arr].forEach((b, i) => {
|
||||||
paddedBytes[i] = b;
|
paddedBytes[i] = b;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1033,8 +1033,10 @@ class Utils {
|
||||||
if (!Utils.isNode()) {
|
if (!Utils.isNode()) {
|
||||||
throw new TypeError("Browser environment cannot support readFileSync");
|
throw new TypeError("Browser environment cannot support readFileSync");
|
||||||
}
|
}
|
||||||
|
// Resist using node's Buffer.buffer here - this yields a 8192 length byteArray
|
||||||
return file.data.buffer;
|
// regardless of the length of the buffer.
|
||||||
|
const arrayBuffer = Uint8Array.from(file.data);
|
||||||
|
return arrayBuffer.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,7 @@ class DishListFile extends DishTranslationType {
|
||||||
*/
|
*/
|
||||||
static toArrayBuffer() {
|
static toArrayBuffer() {
|
||||||
DishListFile.checkForValue(this.value);
|
DishListFile.checkForValue(this.value);
|
||||||
if (Utils.isNode()) {
|
this.value = DishListFile.concatenateTypedArrays(...this.value).buffer;
|
||||||
// TODO
|
|
||||||
this.value = [].concat.apply([], this.value.map(f => Utils.readFileSync(f)).map(b => Array.prototype.slice.call(b)));
|
|
||||||
} else {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
resolve(DishListFile.concatenateTypedArrays(...this.value).buffer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,6 +41,7 @@ let code = `/**
|
||||||
import "babel-polyfill";
|
import "babel-polyfill";
|
||||||
import NodeDish from "./NodeDish";
|
import NodeDish from "./NodeDish";
|
||||||
import { _wrap, help, bake, _explainExludedFunction } from "./api";
|
import { _wrap, help, bake, _explainExludedFunction } from "./api";
|
||||||
|
import File from "./File";
|
||||||
import {
|
import {
|
||||||
// import as core_ to avoid name clashes after wrap.
|
// import as core_ to avoid name clashes after wrap.
|
||||||
`;
|
`;
|
||||||
|
@ -53,6 +54,8 @@ includedOperations.forEach((op) => {
|
||||||
code +=`
|
code +=`
|
||||||
} from "../core/operations/index";
|
} from "../core/operations/index";
|
||||||
|
|
||||||
|
global.File = File;
|
||||||
|
|
||||||
// Define global environment functions
|
// Define global environment functions
|
||||||
global.ENVIRONMENT_IS_WORKER = function() {
|
global.ENVIRONMENT_IS_WORKER = function() {
|
||||||
return typeof importScripts === "function";
|
return typeof importScripts === "function";
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
import "babel-polyfill";
|
import "babel-polyfill";
|
||||||
import NodeDish from "./NodeDish";
|
import NodeDish from "./NodeDish";
|
||||||
import { _wrap, help, bake, _explainExludedFunction } from "./api";
|
import { _wrap, help, bake, _explainExludedFunction } from "./api";
|
||||||
|
import File from "./File";
|
||||||
import {
|
import {
|
||||||
// import as core_ to avoid name clashes after wrap.
|
// import as core_ to avoid name clashes after wrap.
|
||||||
A1Z26CipherDecode as core_A1Z26CipherDecode,
|
A1Z26CipherDecode as core_A1Z26CipherDecode,
|
||||||
|
@ -316,6 +317,8 @@ import {
|
||||||
|
|
||||||
} from "../core/operations/index";
|
} from "../core/operations/index";
|
||||||
|
|
||||||
|
global.File = File;
|
||||||
|
|
||||||
// Define global environment functions
|
// Define global environment functions
|
||||||
global.ENVIRONMENT_IS_WORKER = function() {
|
global.ENVIRONMENT_IS_WORKER = function() {
|
||||||
return typeof importScripts === "function";
|
return typeof importScripts === "function";
|
||||||
|
|
|
@ -79,11 +79,6 @@ export function logTestReport(testStatus, results) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!testStatus.allTestsPassing) {
|
|
||||||
console.log("\nFailing tests:\n");
|
|
||||||
results.filter(r => r.status !== "passing").forEach(handleTestResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue