mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Merge branch 'master' into master
This commit is contained in:
commit
b9571db9f1
14 changed files with 225 additions and 33 deletions
76
src/core/operations/AvroToJSON.mjs
Normal file
76
src/core/operations/AvroToJSON.mjs
Normal file
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* @author jarrodconnolly [jarrod@nestedquotes.ca]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import avro from "avsc";
|
||||
|
||||
/**
|
||||
* Avro to JSON operation
|
||||
*/
|
||||
class AvroToJSON extends Operation {
|
||||
|
||||
/**
|
||||
* AvroToJSON constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Avro to JSON";
|
||||
this.module = "Serialise";
|
||||
this.description = "Converts Avro encoded data into JSON.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Apache_Avro";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Force Valid JSON",
|
||||
type: "boolean",
|
||||
value: true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
if (input.byteLength <= 0) {
|
||||
throw new OperationError("Please provide an input.");
|
||||
}
|
||||
|
||||
const forceJSON = args[0];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const result = [];
|
||||
const inpArray = new Uint8Array(input);
|
||||
const decoder = new avro.streams.BlockDecoder();
|
||||
|
||||
decoder
|
||||
.on("data", function (obj) {
|
||||
result.push(obj);
|
||||
})
|
||||
.on("error", function () {
|
||||
reject(new OperationError("Error parsing Avro file."));
|
||||
})
|
||||
.on("end", function () {
|
||||
if (forceJSON) {
|
||||
resolve(result.length === 1 ? JSON.stringify(result[0], null, 4) : JSON.stringify(result, null, 4));
|
||||
} else {
|
||||
const data = result.reduce((result, current) => result + JSON.stringify(current) + "\n", "");
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
|
||||
decoder.write(inpArray);
|
||||
decoder.end();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default AvroToJSON;
|
|
@ -20,7 +20,7 @@ class BSONDeserialise extends Operation {
|
|||
super();
|
||||
|
||||
this.name = "BSON deserialise";
|
||||
this.module = "BSON";
|
||||
this.module = "Serialise";
|
||||
this.description = "BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures, associative arrays (called objects or documents in MongoDB), and various data types of specific interest to MongoDB. The name 'BSON' is based on the term JSON and stands for 'Binary JSON'.<br><br>Input data should be in a raw bytes format.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/BSON";
|
||||
this.inputType = "ArrayBuffer";
|
||||
|
|
|
@ -20,7 +20,7 @@ class BSONSerialise extends Operation {
|
|||
super();
|
||||
|
||||
this.name = "BSON serialise";
|
||||
this.module = "BSON";
|
||||
this.module = "Serialise";
|
||||
this.description = "BSON is a computer data interchange format used mainly as a data storage and network transfer format in the MongoDB database. It is a binary form for representing simple data structures, associative arrays (called objects or documents in MongoDB), and various data types of specific interest to MongoDB. The name 'BSON' is based on the term JSON and stands for 'Binary JSON'.<br><br>Input data should be valid JSON.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/BSON";
|
||||
this.inputType = "string";
|
||||
|
|
|
@ -47,6 +47,11 @@ class Diff extends Operation {
|
|||
"type": "boolean",
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"name": "Show subtraction",
|
||||
"type": "boolean",
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"name": "Ignore whitespace",
|
||||
"type": "boolean",
|
||||
|
@ -67,6 +72,7 @@ class Diff extends Operation {
|
|||
diffBy,
|
||||
showAdded,
|
||||
showRemoved,
|
||||
showSubtraction,
|
||||
ignoreWhitespace
|
||||
] = args,
|
||||
samples = input.split(sampleDelim);
|
||||
|
@ -116,7 +122,7 @@ class Diff extends Operation {
|
|||
if (showAdded) output += "<span class='hl5'>" + Utils.escapeHtml(diff[i].value) + "</span>";
|
||||
} else if (diff[i].removed) {
|
||||
if (showRemoved) output += "<span class='hl3'>" + Utils.escapeHtml(diff[i].value) + "</span>";
|
||||
} else {
|
||||
} else if (!showSubtraction) {
|
||||
output += Utils.escapeHtml(diff[i].value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue