mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Converted the core to ES modules
This commit is contained in:
parent
c1bb93eec1
commit
9b4fc3d3aa
154 changed files with 1901 additions and 2223 deletions
59
src/core/operations/legacy/BSON.js
Normal file
59
src/core/operations/legacy/BSON.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import bsonjs from "bson";
|
||||
import {Buffer} from "buffer";
|
||||
|
||||
|
||||
/**
|
||||
* BSON operations.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*
|
||||
* @namespace
|
||||
*/
|
||||
const BSON = {
|
||||
|
||||
/**
|
||||
* BSON serialise operation.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
runBSONSerialise(input, args) {
|
||||
if (!input) return new ArrayBuffer();
|
||||
|
||||
const bson = new bsonjs();
|
||||
|
||||
try {
|
||||
const data = JSON.parse(input);
|
||||
return bson.serialize(data).buffer;
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* BSON deserialise operation.
|
||||
*
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*
|
||||
*/
|
||||
runBSONDeserialise(input, args) {
|
||||
if (!input.byteLength) return "";
|
||||
|
||||
const bson = new bsonjs();
|
||||
|
||||
try {
|
||||
const data = bson.deserialize(new Buffer(input));
|
||||
return JSON.stringify(data, null, 2);
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default BSON;
|
Loading…
Add table
Add a link
Reference in a new issue