mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Protobuf operations improved to enable full and partial schema support
This commit is contained in:
parent
a4a13666e6
commit
dd18e52993
7 changed files with 723 additions and 19 deletions
54
src/core/operations/ProtobufEncode.mjs
Normal file
54
src/core/operations/ProtobufEncode.mjs
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @author GCHQ Contributor [3]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Protobuf from "../lib/Protobuf.mjs";
|
||||
|
||||
/**
|
||||
* Protobuf Encode operation
|
||||
*/
|
||||
class ProtobufEncode extends Operation {
|
||||
|
||||
/**
|
||||
* ProtobufEncode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Protobuf Encode";
|
||||
this.module = "Protobuf";
|
||||
this.description = "Encodes a valid JSON object into a protobuf byte array using the input .proto schema.";
|
||||
this.infoURL = "https://developers.google.com/protocol-buffers/docs/encoding";
|
||||
this.inputType = "JSON";
|
||||
this.outputType = "ArrayBuffer";
|
||||
this.args = [
|
||||
{
|
||||
name: "Schema (.proto text)",
|
||||
type: "text",
|
||||
value: "",
|
||||
rows: 8,
|
||||
hint: "Drag and drop is enabled on this ingredient"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} input
|
||||
* @param {Object[]} args
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
return Protobuf.encode(input, args);
|
||||
} catch (error) {
|
||||
throw new OperationError(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ProtobufEncode;
|
Loading…
Add table
Add a link
Reference in a new issue