mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Merge branch 'features/messagepack' of https://github.com/artemisbot/CyberChef into artemisbot-features/messagepack
This commit is contained in:
commit
e7c6a05e9f
6 changed files with 174 additions and 11 deletions
|
@ -47,7 +47,9 @@
|
|||
"Change IP format",
|
||||
"Encode text",
|
||||
"Decode text",
|
||||
"Swap endianness"
|
||||
"Swap endianness",
|
||||
"To MessagePack",
|
||||
"From MessagePack"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
46
src/core/operations/FromMessagePack.mjs
Normal file
46
src/core/operations/FromMessagePack.mjs
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @author Matt C [matt@artemisbot.uk]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import notepack from "notepack.io";
|
||||
|
||||
/**
|
||||
* From MessagePack operation
|
||||
*/
|
||||
class FromMessagePack extends Operation {
|
||||
|
||||
/**
|
||||
* FromMessagePack constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "From MessagePack";
|
||||
this.module = "Code";
|
||||
this.description = "Converts MessagePack encoded data to JSON";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "JSON";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {JSON}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
const buf = Buffer.from(new Uint8Array(input));
|
||||
return notepack.decode(buf);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Could not decode MessagePack to JSON: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default FromMessagePack;
|
49
src/core/operations/ToMessagePack.mjs
Normal file
49
src/core/operations/ToMessagePack.mjs
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* @author Matt C [matt@artemisbot.uk]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import notepack from "notepack.io";
|
||||
|
||||
/**
|
||||
* To MessagePack operation
|
||||
*/
|
||||
class ToMessagePack extends Operation {
|
||||
|
||||
/**
|
||||
* ToMessagePack constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "To MessagePack";
|
||||
this.module = "Code";
|
||||
this.description = "Converts JSON to MessagePack encoded byte buffer";
|
||||
this.inputType = "JSON";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JSON} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
if (ENVIRONMENT_IS_WORKER()) {
|
||||
return notepack.encode(input);
|
||||
} else {
|
||||
return notepack.encode(input).buffer;
|
||||
}
|
||||
} catch (err) {
|
||||
throw new OperationError(`Could not encode JSON to MessagePack: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ToMessagePack;
|
Loading…
Add table
Add a link
Reference in a new issue