mirror of
https://github.com/gchq/CyberChef
synced 2024-12-29 14:03:10 +00:00
RISON operation
This commit is contained in:
parent
1bc88728f0
commit
9a216dc1bf
7 changed files with 205 additions and 1 deletions
11
package-lock.json
generated
11
package-lock.json
generated
|
@ -78,6 +78,7 @@
|
||||||
"protobufjs": "^7.2.2",
|
"protobufjs": "^7.2.2",
|
||||||
"qr-image": "^3.2.0",
|
"qr-image": "^3.2.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rison": "^0.1.1",
|
||||||
"scryptsy": "^2.1.0",
|
"scryptsy": "^2.1.0",
|
||||||
"snackbarjs": "^1.1.0",
|
"snackbarjs": "^1.1.0",
|
||||||
"sortablejs": "^1.15.0",
|
"sortablejs": "^1.15.0",
|
||||||
|
@ -11704,6 +11705,11 @@
|
||||||
"inherits": "^2.0.1"
|
"inherits": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/rison": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/rison/-/rison-0.1.1.tgz",
|
||||||
|
"integrity": "sha512-8C+/PKKTaAYE2quDtOUwny/eQpNn9YGby7T80wntbVWSGvw0aUT9M0YgLdLkUgIQzQwaB1ZTr80rwLVKyohHig=="
|
||||||
|
},
|
||||||
"node_modules/robust-predicates": {
|
"node_modules/robust-predicates": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"license": "Unlicense"
|
"license": "Unlicense"
|
||||||
|
@ -21755,6 +21761,11 @@
|
||||||
"inherits": "^2.0.1"
|
"inherits": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"rison": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/rison/-/rison-0.1.1.tgz",
|
||||||
|
"integrity": "sha512-8C+/PKKTaAYE2quDtOUwny/eQpNn9YGby7T80wntbVWSGvw0aUT9M0YgLdLkUgIQzQwaB1ZTr80rwLVKyohHig=="
|
||||||
|
},
|
||||||
"robust-predicates": {
|
"robust-predicates": {
|
||||||
"version": "3.0.1"
|
"version": "3.0.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -160,6 +160,7 @@
|
||||||
"protobufjs": "^7.2.2",
|
"protobufjs": "^7.2.2",
|
||||||
"qr-image": "^3.2.0",
|
"qr-image": "^3.2.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rison": "^0.1.1",
|
||||||
"scryptsy": "^2.1.0",
|
"scryptsy": "^2.1.0",
|
||||||
"snackbarjs": "^1.1.0",
|
"snackbarjs": "^1.1.0",
|
||||||
"sortablejs": "^1.15.0",
|
"sortablejs": "^1.15.0",
|
||||||
|
|
|
@ -67,7 +67,9 @@
|
||||||
"JSON to CSV",
|
"JSON to CSV",
|
||||||
"Avro to JSON",
|
"Avro to JSON",
|
||||||
"CBOR Encode",
|
"CBOR Encode",
|
||||||
"CBOR Decode"
|
"CBOR Decode",
|
||||||
|
"Rison Encode",
|
||||||
|
"Rison Decode"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
60
src/core/operations/RisonDecode.mjs
Normal file
60
src/core/operations/RisonDecode.mjs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* @author sg5506844 [sg5506844@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import rison from "rison";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rison Decode operation
|
||||||
|
*/
|
||||||
|
class RisonDecode extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RisonDecode constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Rison Decode";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Rison, a data serialization format optimized for compactness in URIs. Rison is a slight variation of JSON that looks vastly superior after URI encoding. Rison still expresses exactly the same set of data structures as JSON, so data can be translated back and forth without loss or guesswork.";
|
||||||
|
this.infoURL = "https://github.com/Nanonid/rison";
|
||||||
|
this.inputType = "string";
|
||||||
|
this.outputType = "Object";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Decode Option",
|
||||||
|
type: "editableOption",
|
||||||
|
value: [
|
||||||
|
{ name: "Decode", value: "Decode", },
|
||||||
|
{ name: "Decode Object", value: "Decode Object", },
|
||||||
|
{ name: "Decode Array", value: "Decode Array", },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const [decodeOption] = args;
|
||||||
|
switch (decodeOption) {
|
||||||
|
case "Decode":
|
||||||
|
return rison.decode(input);
|
||||||
|
case "Decode Object":
|
||||||
|
return rison.decode_object(input);
|
||||||
|
case "Decode Array":
|
||||||
|
return rison.decode_array(input);
|
||||||
|
}
|
||||||
|
throw new OperationError("Invalid Decode option");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RisonDecode;
|
63
src/core/operations/RisonEncode.mjs
Normal file
63
src/core/operations/RisonEncode.mjs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
* @author sg5506844 [sg5506844@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation.mjs";
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
|
import rison from "rison";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rison Encode operation
|
||||||
|
*/
|
||||||
|
class RisonEncode extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RisonEncode constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Rison Encode";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Rison, a data serialization format optimized for compactness in URIs. Rison is a slight variation of JSON that looks vastly superior after URI encoding. Rison still expresses exactly the same set of data structures as JSON, so data can be translated back and forth without loss or guesswork.";
|
||||||
|
this.infoURL = "https://github.com/Nanonid/rison";
|
||||||
|
this.inputType = "Object";
|
||||||
|
this.outputType = "string";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Encode Option",
|
||||||
|
type: "editableOption",
|
||||||
|
value: [
|
||||||
|
{ name: "Encode", value: "Encode", },
|
||||||
|
{ name: "Encode Object", value: "Encode Object", },
|
||||||
|
{ name: "Encode Array", value: "Encode Array", },
|
||||||
|
{ name: "Encode URI", value: "Encode URI", }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const [encodeOption] = args;
|
||||||
|
switch (encodeOption) {
|
||||||
|
case "Encode":
|
||||||
|
return rison.encode(input);
|
||||||
|
case "Encode Object":
|
||||||
|
return rison.encode_object(input);
|
||||||
|
case "Encode Array":
|
||||||
|
return rison.encode_array(input);
|
||||||
|
case "Encode URI":
|
||||||
|
return rison.encode_uri(input);
|
||||||
|
}
|
||||||
|
throw new OperationError("Invalid encode option");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RisonEncode;
|
|
@ -113,6 +113,7 @@ import "./tests/Unicode.mjs";
|
||||||
import "./tests/RSA.mjs";
|
import "./tests/RSA.mjs";
|
||||||
import "./tests/CBOREncode.mjs";
|
import "./tests/CBOREncode.mjs";
|
||||||
import "./tests/CBORDecode.mjs";
|
import "./tests/CBORDecode.mjs";
|
||||||
|
import "./tests/RisonEncodeDecode.mjs";
|
||||||
import "./tests/JA3Fingerprint.mjs";
|
import "./tests/JA3Fingerprint.mjs";
|
||||||
import "./tests/JA3SFingerprint.mjs";
|
import "./tests/JA3SFingerprint.mjs";
|
||||||
import "./tests/HASSH.mjs";
|
import "./tests/HASSH.mjs";
|
||||||
|
|
66
tests/operations/tests/RisonEncodeDecode.mjs
Normal file
66
tests/operations/tests/RisonEncodeDecode.mjs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
* @author sg5506844 [sg5506844@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2021
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Rison Encode: Encoding example 1",
|
||||||
|
input: JSON.stringify({ any: "json", yes: true }),
|
||||||
|
expectedOutput: "(any:json,yes:!t)",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Rison Encode",
|
||||||
|
args: ["Encode"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Rison Encode: Encoding example 2",
|
||||||
|
input: JSON.stringify({ supportsObjects: true, ints: 435 }),
|
||||||
|
expectedOutput: "ints:435,supportsObjects:!t",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Rison Encode",
|
||||||
|
args: ["Encode Object"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Rison Encode: Encoding example 3",
|
||||||
|
input: JSON.stringify(["A", "B", { supportsObjects: true }]),
|
||||||
|
expectedOutput: "A,B,(supportsObjects:!t)",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Rison Encode",
|
||||||
|
args: ["Encode Array"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Rison Encode: Object for an array",
|
||||||
|
input: JSON.stringify({ supportsObjects: true, ints: 435 }),
|
||||||
|
expectedOutput: "Rison Encode - rison.encode_array expects an array argument",
|
||||||
|
expectedError: "Rison Encode - rison.encode_array expects an array argument",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Rison Encode",
|
||||||
|
args: ["Encode Array"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Rison Decode: Decoding example 1",
|
||||||
|
input: "(any:json,yes:!t)",
|
||||||
|
expectedOutput: JSON.stringify({ any: "json", yes: true }, null, 4),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Rison Decode",
|
||||||
|
args: ["Decode"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
Loading…
Reference in a new issue