mirror of
https://github.com/gchq/CyberChef
synced 2025-01-08 10:38:46 +00:00
in/out typing working. Added translateTo function
This commit is contained in:
parent
7e7e5e7466
commit
c238862efe
3 changed files with 23 additions and 8 deletions
|
@ -39,6 +39,7 @@ class Dish {
|
||||||
*/
|
*/
|
||||||
static typeEnum(typeStr) {
|
static typeEnum(typeStr) {
|
||||||
switch (typeStr.toLowerCase()) {
|
switch (typeStr.toLowerCase()) {
|
||||||
|
case "array":
|
||||||
case "bytearray":
|
case "bytearray":
|
||||||
case "byte array":
|
case "byte array":
|
||||||
return Dish.BYTE_ARRAY;
|
return Dish.BYTE_ARRAY;
|
||||||
|
|
|
@ -35,13 +35,12 @@ export function wrap(Operation) {
|
||||||
*/
|
*/
|
||||||
return async (input, args=null) => {
|
return async (input, args=null) => {
|
||||||
const operation = new Operation();
|
const operation = new Operation();
|
||||||
const dish = new Dish(input);
|
const dish = new Dish();
|
||||||
|
|
||||||
try {
|
// Stolen from Recipe. Only works there as raw input is one
|
||||||
dish.findType();
|
// of these types. consider a mapping for all use cases like below.
|
||||||
} catch (e) {
|
const type = input instanceof ArrayBuffer ? Dish.ARRAY_BUFFER : Dish.STRING;
|
||||||
log.debug(e);
|
dish.set(input, type);
|
||||||
}
|
|
||||||
|
|
||||||
if (!args) {
|
if (!args) {
|
||||||
args = operation.args.map(extractArg);
|
args = operation.args.map(extractArg);
|
||||||
|
@ -51,11 +50,25 @@ export function wrap(Operation) {
|
||||||
args = [args];
|
args = [args];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const transformedInput = await dish.get(Dish.typeEnum(operation.inputType));
|
const transformedInput = await dish.get(operation.inputType);
|
||||||
return operation.run(transformedInput, args);
|
return operation.run(transformedInput, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First draft
|
||||||
|
* @param input
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
export async function translateTo(input, type) {
|
||||||
|
const dish = new Dish();
|
||||||
|
|
||||||
|
const initialType = Dish.typeEnum(input.constructor.name);
|
||||||
|
|
||||||
|
dish.set(input, initialType);
|
||||||
|
return await dish.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param searchTerm
|
* @param searchTerm
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
import "babel-polyfill";
|
import "babel-polyfill";
|
||||||
|
|
||||||
import {wrap, help, decapitalise} from "./apiUtils";
|
import {wrap, help, decapitalise, translateTo} from "./apiUtils";
|
||||||
import * as operations from "../core/operations/index";
|
import * as operations from "../core/operations/index";
|
||||||
|
|
||||||
// Define global environment functions
|
// Define global environment functions
|
||||||
|
@ -29,6 +29,7 @@ Object.keys(operations).forEach(op =>
|
||||||
chef[decapitalise(op)] = wrap(operations[op]));
|
chef[decapitalise(op)] = wrap(operations[op]));
|
||||||
|
|
||||||
chef.help = help.bind(null, operations);
|
chef.help = help.bind(null, operations);
|
||||||
|
chef.translateTo = translateTo;
|
||||||
|
|
||||||
export default chef;
|
export default chef;
|
||||||
export {chef};
|
export {chef};
|
||||||
|
|
Loading…
Reference in a new issue