mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-02 22:21:01 +01:00
Remove Buffer from Dish. Convert into ByteArray in api and then pass in as ArrayBuffer. Add some PNG files to tests
This commit is contained in:
parent
20bb104006
commit
55f7cac526
@ -61,8 +61,6 @@ class Dish {
|
||||
return Dish.FILE;
|
||||
case "list<file>":
|
||||
return Dish.LIST_FILE;
|
||||
case "buffer":
|
||||
return Dish.BUFFER;
|
||||
default:
|
||||
throw "Invalid data type string. No matching enum.";
|
||||
}
|
||||
@ -95,8 +93,6 @@ class Dish {
|
||||
return "File";
|
||||
case Dish.LIST_FILE:
|
||||
return "List<File>";
|
||||
case Dish.BUFFER:
|
||||
return "Buffer";
|
||||
default:
|
||||
throw "Invalid data type enum. No matching type.";
|
||||
}
|
||||
@ -270,8 +266,6 @@ class Dish {
|
||||
case Dish.LIST_FILE:
|
||||
return this.value instanceof Array &&
|
||||
this.value.reduce((acc, curr) => acc && curr instanceof File, true);
|
||||
case Dish.BUFFER:
|
||||
return this.value instanceof Buffer;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -290,7 +284,6 @@ class Dish {
|
||||
case Dish.BYTE_ARRAY:
|
||||
case Dish.STRING:
|
||||
case Dish.HTML:
|
||||
case Dish.BUFFER:
|
||||
return this.value.length;
|
||||
case Dish.NUMBER:
|
||||
case Dish.BIG_NUMBER:
|
||||
@ -364,12 +357,6 @@ class Dish {
|
||||
this.type
|
||||
);
|
||||
break;
|
||||
case Dish.BUFFER:
|
||||
newDish.set(
|
||||
Buffer.from(this.value),
|
||||
this.type
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Cannot clone Dish, unknown type");
|
||||
}
|
||||
@ -434,12 +421,5 @@ Dish.FILE = 7;
|
||||
* @enum
|
||||
*/
|
||||
Dish.LIST_FILE = 8;
|
||||
/**
|
||||
* Dish data type enum for node Buffer.
|
||||
* @readonly
|
||||
* @enum
|
||||
*/
|
||||
Dish.BUFFER = 9;
|
||||
|
||||
|
||||
export default Dish;
|
||||
|
@ -108,15 +108,20 @@ function ensureIsDish(input) {
|
||||
dish.set(input, type);
|
||||
}
|
||||
return dish;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* prepareOp: transform args, make input the right type.
|
||||
* Also convert any Buffers to ArrayBuffers.
|
||||
* @param opInstance - instance of the operation
|
||||
* @param input - operation input
|
||||
* @param args - operation args
|
||||
*/
|
||||
function prepareOp(opInstance, input, args) {
|
||||
// convert any Buffers into ArrayBuffers.
|
||||
if (input instanceof Buffer) {
|
||||
input = input.buffer;
|
||||
}
|
||||
const dish = ensureIsDish(input);
|
||||
let transformedArgs;
|
||||
// Transform object-style args to original args array
|
||||
@ -127,7 +132,7 @@ function prepareOp(opInstance, input, args) {
|
||||
}
|
||||
const transformedInput = dish.get(opInstance.inputType);
|
||||
return {transformedInput, transformedArgs};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an operation to be consumed by node API.
|
||||
|
@ -786,29 +786,13 @@ jmPGsv1elXxVzqs58UZLD2c3vBhGkU2BV6kRKh+lj/EcVrzsFhGCz/7DKxPoDHLS
|
||||
|
||||
it("Remove EXIF", () => {
|
||||
const result = chef.removeEXIF(fs.readFileSync("test/tests/nodeApi/sampleData/pic.jpg"));
|
||||
assert.strictEqual(result.toString().length(), 4582);
|
||||
assert.strictEqual(result.toString().length, 4582);
|
||||
}),
|
||||
|
||||
it("Scan for embedded files", () => {
|
||||
const result = chef.scanForEmbeddedFiles(fs.readFileSync("test/tests/nodeApi/sampleData/pic.jpg"));
|
||||
const expected = `Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.
|
||||
|
||||
Offset 0 (0x00):
|
||||
File extension: jpg
|
||||
MIME type: image/jpeg
|
||||
|
||||
Offset 30 (0x1e):
|
||||
File extension: tif
|
||||
MIME type: image/tiff
|
||||
|
||||
Offset 212 (0xd4):
|
||||
File extension: txt
|
||||
MIME type: text/plain
|
||||
Description: UTF-8 encoded Unicode byte order mark detected, commonly but not exclusively seen in text files.
|
||||
|
||||
|
||||
16 file types were detected that have common byte sequences. These are likely to be false positives. Run this operation with the 'Ignore common byte sequences' option unchecked to see details.`;
|
||||
assert.strictEqual(result.toString(), expected);
|
||||
const result = chef.scanForEmbeddedFiles(fs.readFileSync("src/web/static/images/cook_male-32x32.png"));
|
||||
const expected = "Scanning data for \'magic bytes\' which may indicate embedded files.";
|
||||
assert.ok(result.toString().indexOf(expected) === 0);
|
||||
}),
|
||||
|
||||
it("Scrypt", () => {
|
||||
@ -950,9 +934,9 @@ smothering ampersand abreast
|
||||
|
||||
it("Detect file type", () => {
|
||||
assert.strictEqual(
|
||||
chef.detectFileType(fs.readFileSync("test/tests/nodeApi/sampleData/pic.jpg")).toString(),
|
||||
`File extension: jpg
|
||||
MIME type: image/jpeg`);
|
||||
chef.detectFileType(fs.readFileSync("src/web/static/images/cook_male-32x32.png")).toString(),
|
||||
`File extension: png
|
||||
MIME type: image/png`);
|
||||
}),
|
||||
|
||||
it("extract EXIF", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user