Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISON operation #1555

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,468 changes: 7 additions & 10,461 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"protobufjs": "^7.2.6",
"qr-image": "^3.2.0",
"reflect-metadata": "^0.2.1",
"rison": "^0.1.1",
"scryptsy": "^2.1.0",
"snackbarjs": "^1.1.0",
"sortablejs": "^1.15.2",
Expand Down
4 changes: 3 additions & 1 deletion src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
"JSON to CSV",
"Avro to JSON",
"CBOR Encode",
"CBOR Decode"
"CBOR Decode",
"Rison Encode",
"Rison Decode"
]
},
{
Expand Down
11 changes: 0 additions & 11 deletions src/core/operations/AnalyseHash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ class AnalyseHash extends Operation {
run(input, args) {
input = input.replace(/\s/g, "");

// analyze hash if it is bcrypt
if (/^\$2[abxy]?\$[0-9]+\$[a-zA-Z0-9/.]{53}$/.test(input)) {
input = input.split("$");
return "Hash algorithm Identifier: $" + input[1] + "$\n" +
"Rounds: " + input[2] + "\n" +
"Base64 encoded Input salt(22 bytes): " + input[3].slice(0, 22) + "\n" +
"Base64 encoded hash(31 bytes): " + input[3].slice(22) + "\n\n" +
"Based on the length, this hash could have been generated by one of the following hashing functions:\n" +
"bcrypt";
}

let output = "",
possibleHashFunctions = [];
const byteLength = input.length / 2,
Expand Down
60 changes: 60 additions & 0 deletions src/core/operations/RisonDecode.mjs
Original file line number Diff line number Diff line change
@@ -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 changes: 63 additions & 0 deletions src/core/operations/RisonEncode.mjs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 1 addition & 5 deletions src/web/waiters/RecipeWaiter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,7 @@ class RecipeWaiter {
const item = document.createElement("li");

item.classList.add("operation");

if (this.app.operations[name] != null) {
item.innerHTML = name;
}

item.innerHTML = name;
this.buildRecipeOperation(item);
document.getElementById("rec-list").appendChild(item);

Expand Down
1 change: 1 addition & 0 deletions tests/operations/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import "./tests/Unicode.mjs";
import "./tests/RSA.mjs";
import "./tests/CBOREncode.mjs";
import "./tests/CBORDecode.mjs";
import "./tests/RisonEncodeDecode.mjs";
import "./tests/JA3Fingerprint.mjs";
import "./tests/JA3SFingerprint.mjs";
import "./tests/HASSH.mjs";
Expand Down
66 changes: 66 additions & 0 deletions tests/operations/tests/RisonEncodeDecode.mjs
Original file line number Diff line number Diff line change
@@ -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