Rename operation, add working tests, add info URL
This commit is contained in:
parent
3abe99078e
commit
3833c5f9fe
@ -54,7 +54,7 @@
|
|||||||
"From MessagePack",
|
"From MessagePack",
|
||||||
"To Braille",
|
"To Braille",
|
||||||
"From Braille",
|
"From Braille",
|
||||||
"From Length Value"
|
"LV Decode"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -8,61 +8,40 @@ import Operation from "../Operation";
|
|||||||
import LengthValue from "../lib/LengthValue";
|
import LengthValue from "../lib/LengthValue";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From Length Value operation
|
* From LV Decode operation
|
||||||
*/
|
*/
|
||||||
class FromLengthValue extends Operation {
|
class LVDecode extends Operation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FromLengthValue constructor
|
* LVDecode constructor
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = "From Length Value";
|
this.name = "LV Decode";
|
||||||
this.module = "Default";
|
this.module = "Default";
|
||||||
this.description = "Converts a Length-Value (LV) encoded string into a JSON object. Can optionally include a <code>Key</code> / <code>Type</code> entry.";
|
this.description = "Converts a Length-Value (LV) encoded string into a JSON object. Can optionally include a <code>Key</code> / <code>Type</code> entry.";
|
||||||
this.infoURL = "";
|
this.infoURL = "https://wikipedia.org/wiki/KLV";
|
||||||
this.inputType = "byteArray";
|
this.inputType = "byteArray";
|
||||||
this.outputType = "JSON";
|
this.outputType = "JSON";
|
||||||
this.args = [
|
this.args = [
|
||||||
{
|
{
|
||||||
name: "Bytes in Key Value",
|
name: "Bytes in Key Value",
|
||||||
type: "populateOption",
|
type: "option",
|
||||||
value: [
|
value: [
|
||||||
{
|
"0 Bytes (No Key)",
|
||||||
name: "0 Bytes (No Key)",
|
"1 Byte",
|
||||||
value: "0"
|
"2 Bytes",
|
||||||
},
|
"4 Bytes"
|
||||||
{
|
|
||||||
name: "1 Byte",
|
|
||||||
value: "1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "2 Bytes",
|
|
||||||
value: "2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "4 Bytes",
|
|
||||||
value: "4"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bytes in Length Value",
|
name: "Bytes in Length Value",
|
||||||
type: "populateOption",
|
type: "option",
|
||||||
value: [
|
value: [
|
||||||
{
|
"1 Byte",
|
||||||
name: "1 Byte",
|
"2 Bytes",
|
||||||
value: "1"
|
"4 Bytes"
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "2 Bytes",
|
|
||||||
value: "2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "4 Bytes",
|
|
||||||
value: "4"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -99,4 +78,4 @@ class FromLengthValue extends Operation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FromLengthValue;
|
export default LVDecode;
|
@ -64,7 +64,7 @@ import "./tests/operations/SetUnion";
|
|||||||
import "./tests/operations/SymmetricDifference";
|
import "./tests/operations/SymmetricDifference";
|
||||||
import "./tests/operations/TranslateDateTimeFormat";
|
import "./tests/operations/TranslateDateTimeFormat";
|
||||||
import "./tests/operations/Magic";
|
import "./tests/operations/Magic";
|
||||||
import "./tests/operations/LengthValueDecoder";
|
import "./tests/operations/LVDecode";
|
||||||
|
|
||||||
let allTestsPassing = true;
|
let allTestsPassing = true;
|
||||||
const testStatusCounts = {
|
const testStatusCounts = {
|
||||||
|
56
test/tests/operations/LVDecode.mjs
Normal file
56
test/tests/operations/LVDecode.mjs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* LV Decoder tests.
|
||||||
|
*
|
||||||
|
* @author gchq77703 []
|
||||||
|
* @copyright Crown Copyright 2018
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TestRegister from "../../TestRegister";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "LVDecode: LengthValue",
|
||||||
|
input: "\x05\x48\x6f\x75\x73\x65\x04\x72\x6f\x6f\x6d\x04\x64\x6f\x6f\x72",
|
||||||
|
expectedOutput: JSON.stringify([{"length": 5, "value": [72, 111, 117, 115, 101]}, {"length": 4, "value": [114, 111, 111, 109]}, {"length": 4, "value": [100, 111, 111, 114]}]),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "LV Decode",
|
||||||
|
"args": ["0 Bytes (No Key)", "1 Byte", false]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "LVDecode: LengthValue with BER",
|
||||||
|
input: "\x05\x48\x6f\x75\x73\x65\x04\x72\x6f\x6f\x6d\x04\x64\x6f\x6f\x72",
|
||||||
|
expectedOutput: JSON.stringify([{"length": 5, "value": [72, 111, 117, 115, 101]}, {"length": 4, "value": [114, 111, 111, 109]}, {"length": 4, "value": [100, 111, 111, 114]}]),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "LV Decode",
|
||||||
|
"args": ["0 Bytes (No Key)", "4 Bytes", false] // length value is patently wrong, should be ignored by BER.
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "LVDecode: KeyLengthValue",
|
||||||
|
input: "\x04\x05\x48\x6f\x75\x73\x65\x05\x04\x72\x6f\x6f\x6d\x42\x04\x64\x6f\x6f\x72",
|
||||||
|
expectedOutput: JSON.stringify([{"key":[4],"length":5,"value":[72,111,117,115,101]},{"key":[5],"length":4,"value":[114,111,111,109]},{"key":[66],"length":4,"value":[100,111,111,114]}]),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "LV Decode",
|
||||||
|
"args": ["1 Byte", "1 Byte", false]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "LVDecode: KeyLengthValue with BER",
|
||||||
|
input: "\x04\x05\x48\x6f\x75\x73\x65\x05\x04\x72\x6f\x6f\x6d\x42\x04\x64\x6f\x6f\x72",
|
||||||
|
expectedOutput: JSON.stringify([{"key":[4],"length":5,"value":[72,111,117,115,101]},{"key":[5],"length":4,"value":[114,111,111,109]},{"key":[66],"length":4,"value":[100,111,111,114]}]),
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "LV Decode",
|
||||||
|
"args": ["1 Byte", "4 Byte", true] // length value is patently wrong, should be ignored by BER.
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
@ -1,23 +0,0 @@
|
|||||||
/**
|
|
||||||
* Length Value Decoder tests.
|
|
||||||
*
|
|
||||||
* @author gchq77703 []
|
|
||||||
* @copyright Crown Copyright 2018
|
|
||||||
* @license Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
import TestRegister from "../../TestRegister";
|
|
||||||
|
|
||||||
TestRegister.addTests([
|
|
||||||
{
|
|
||||||
name: "KeyValue",
|
|
||||||
input: [5, 72, 111, 117, 115, 101, 4, 114, 111, 111, 109, 4, 100, 111, 111, 114],
|
|
||||||
expectedOutput: [{"key": [25], "length": 5, "value": [72, 111, 117, 115, 101]}, {"key": [73], "length": 4, "value": [114, 111, 111, 109]}, {"key": [41], "length": 4, "value": [100, 111, 111, 114]}],
|
|
||||||
recipeConfig: [
|
|
||||||
{
|
|
||||||
"op": "Length Value Decoder",
|
|
||||||
"args": ["0 Bytes (No Key)", "1 Byte", false]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]);
|
|
Loading…
x
Reference in New Issue
Block a user