mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
add operation input case to chef.search
This commit is contained in:
parent
2ff7b5902c
commit
a4d7065e42
3 changed files with 29 additions and 6 deletions
|
@ -89,7 +89,7 @@ export function wrap(OpClass) {
|
||||||
* @returns {SyncDish} operation's output, on a Dish.
|
* @returns {SyncDish} operation's output, on a Dish.
|
||||||
* @throws {OperationError} if the operation throws one.
|
* @throws {OperationError} if the operation throws one.
|
||||||
*/
|
*/
|
||||||
return (input, args=null) => {
|
const wrapped = (input, args=null) => {
|
||||||
const operation = new OpClass();
|
const operation = new OpClass();
|
||||||
|
|
||||||
let dish;
|
let dish;
|
||||||
|
@ -108,6 +108,10 @@ export function wrap(OpClass) {
|
||||||
type: operation.outputType
|
type: operation.outputType
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// used in chef.help
|
||||||
|
wrapped.opName = OpClass.name;
|
||||||
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,15 +167,23 @@ function extractOperationInfo(Operation) {
|
||||||
*/
|
*/
|
||||||
export function help(operations) {
|
export function help(operations) {
|
||||||
return function(searchTerm) {
|
return function(searchTerm) {
|
||||||
|
let sanitised = false;
|
||||||
if (typeof searchTerm === "string") {
|
if (typeof searchTerm === "string") {
|
||||||
|
sanitised = searchTerm;
|
||||||
|
} else if (typeof searchTerm === "function") {
|
||||||
|
sanitised = searchTerm.opName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sanitised) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const operation = operations
|
const operation = operations
|
||||||
.find(o => o.name.toLowerCase() === searchTerm.replace(/ /g, "").toLowerCase());
|
.find(o => o.name.toLowerCase() === sanitised.replace(/ /g, "").toLowerCase());
|
||||||
if (operation) {
|
if (operation) {
|
||||||
return extractOperationInfo(operation);
|
return extractOperationInfo(operation);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,4 +127,10 @@ TestRegister.addApiTests([
|
||||||
const result = chef.help("some invalid function name");
|
const result = chef.help("some invalid function name");
|
||||||
assert.strictEqual(result, null);
|
assert.strictEqual(result, null);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("chef.help: takes a wrapped operation as input", () => {
|
||||||
|
const result = chef.help(chef.toBase32);
|
||||||
|
assert.strictEqual(result.name, "toBase32");
|
||||||
|
assert.strictEqual(result.module, "Default");
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -134,5 +134,10 @@ color: white;
|
||||||
assert.strictEqual(result.toString(), "SPI1R1T0");
|
assert.strictEqual(result.toString(), "SPI1R1T0");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("toBase64: editableOptions default", () => {
|
||||||
|
const result = toBase64("some input");
|
||||||
|
assert.strictEqual(result.toString(), "c29tZSBpbnB1dA==");
|
||||||
|
}),
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue