mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 06:55:08 -04:00
improve some comments, remove unused properties from magic state shim in node API
This commit is contained in:
parent
53e69835ff
commit
4dafa50799
4 changed files with 16 additions and 15 deletions
|
@ -24,8 +24,11 @@ class NodeRecipe {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate an ingredient $ coerce to operation if necessary.
|
* Validate an ingredient & coerce to operation if necessary.
|
||||||
* @param {String | Function | Object} ing
|
* @param {String | Function | Object} ing
|
||||||
|
* @returns {Function || Object} The operation, or an object with the
|
||||||
|
* operation and its arguments
|
||||||
|
* @throws {TypeError} If it cannot find the operation in chef's list of operations.
|
||||||
*/
|
*/
|
||||||
_validateIngredient(ing) {
|
_validateIngredient(ing) {
|
||||||
// CASE operation name given. Find operation and validate
|
// CASE operation name given. Find operation and validate
|
||||||
|
@ -34,6 +37,7 @@ class NodeRecipe {
|
||||||
return sanitise(op.opName) === sanitise(ing);
|
return sanitise(op.opName) === sanitise(ing);
|
||||||
});
|
});
|
||||||
if (op) {
|
if (op) {
|
||||||
|
// Need to validate against case 2
|
||||||
return this._validateIngredient(op);
|
return this._validateIngredient(op);
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(`Couldn't find an operation with name '${ing}'.`);
|
throw new TypeError(`Couldn't find an operation with name '${ing}'.`);
|
||||||
|
@ -41,7 +45,7 @@ class NodeRecipe {
|
||||||
// CASE operation given. Check its a chef operation and check its not flowcontrol
|
// CASE operation given. Check its a chef operation and check its not flowcontrol
|
||||||
} else if (typeof ing === "function") {
|
} else if (typeof ing === "function") {
|
||||||
if (ing.flowControl) {
|
if (ing.flowControl) {
|
||||||
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake`);
|
throw new TypeError(`flowControl operations like ${ing.opName} are not currently allowed in recipes for chef.bake in the Node API`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operations.includes(ing)) {
|
if (operations.includes(ing)) {
|
||||||
|
@ -63,7 +67,7 @@ class NodeRecipe {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse config for recipe.
|
* Parse an opList from a recipeConfig and assign it to the recipe's opList.
|
||||||
* @param {String | Function | String[] | Function[] | [String | Function]} recipeConfig
|
* @param {String | Function | String[] | Function[] | [String | Function]} recipeConfig
|
||||||
*/
|
*/
|
||||||
_parseConfig(recipeConfig) {
|
_parseConfig(recipeConfig) {
|
||||||
|
|
|
@ -194,17 +194,14 @@ export function _wrap(OpClass) {
|
||||||
const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args);
|
const {transformedInput, transformedArgs} = prepareOp(opInstance, input, args);
|
||||||
|
|
||||||
// SPECIAL CASE for Magic. Other flowControl operations will
|
// SPECIAL CASE for Magic. Other flowControl operations will
|
||||||
// not work because the opList is not passed through.
|
// not work because the opList is not passed in.
|
||||||
if (isFlowControl) {
|
if (isFlowControl) {
|
||||||
opInstance.ingValues = transformedArgs;
|
opInstance.ingValues = transformedArgs;
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
"progress": 0,
|
progress: 0,
|
||||||
"dish": ensureIsDish(transformedInput),
|
dish: ensureIsDish(transformedInput),
|
||||||
"opList": [opInstance],
|
opList: [opInstance],
|
||||||
"numJumps": 0,
|
|
||||||
"numRegisters": 0,
|
|
||||||
"forkOffset": 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatedState = await opInstance.run(state);
|
const updatedState = await opInstance.run(state);
|
||||||
|
|
|
@ -348,15 +348,15 @@ TestRegister.addApiTests([
|
||||||
it("chef.bake: cannot accept flowControl operations in recipe", () => {
|
it("chef.bake: cannot accept flowControl operations in recipe", () => {
|
||||||
assert.throws(() => chef.bake("some input", "magic"), {
|
assert.throws(() => chef.bake("some input", "magic"), {
|
||||||
name: "TypeError",
|
name: "TypeError",
|
||||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
|
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
|
||||||
});
|
});
|
||||||
assert.throws(() => chef.bake("some input", magic), {
|
assert.throws(() => chef.bake("some input", magic), {
|
||||||
name: "TypeError",
|
name: "TypeError",
|
||||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
|
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
|
||||||
});
|
});
|
||||||
assert.throws(() => chef.bake("some input", ["to base 64", "magic"]), {
|
assert.throws(() => chef.bake("some input", ["to base 64", "magic"]), {
|
||||||
name: "TypeError",
|
name: "TypeError",
|
||||||
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake"
|
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
@ -1077,10 +1077,10 @@ ExifImageHeight: 57`);
|
||||||
|
|
||||||
it("performs MAGIC", async () => {
|
it("performs MAGIC", async () => {
|
||||||
const input = "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP";
|
const input = "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP";
|
||||||
const depth = 3;
|
const depth = 1;
|
||||||
|
|
||||||
const res = await chef.magic(input, {
|
const res = await chef.magic(input, {
|
||||||
depth: 3
|
depth,
|
||||||
});
|
});
|
||||||
|
|
||||||
// assert against the structure of the output, rather than the values.
|
// assert against the structure of the output, rather than the values.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue