Skip to content

Commit 3833c5f

Browse files
author
GCHQ 77703
committed
Rename operation, add working tests, add info URL
1 parent 3abe990 commit 3833c5f

File tree

5 files changed

+73
-61
lines changed

5 files changed

+73
-61
lines changed

src/core/config/Categories.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"From MessagePack",
5555
"To Braille",
5656
"From Braille",
57-
"From Length Value"
57+
"LV Decode"
5858
]
5959
},
6060
{

src/core/operations/LengthValueDecoder.mjs src/core/operations/LVDecode.mjs

+15-36
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,40 @@ import Operation from "../Operation";
88
import LengthValue from "../lib/LengthValue";
99

1010
/**
11-
* From Length Value operation
11+
* From LV Decode operation
1212
*/
13-
class FromLengthValue extends Operation {
13+
class LVDecode extends Operation {
1414

1515
/**
16-
* FromLengthValue constructor
16+
* LVDecode constructor
1717
*/
1818
constructor() {
1919
super();
2020

21-
this.name = "From Length Value";
21+
this.name = "LV Decode";
2222
this.module = "Default";
2323
this.description = "Converts a Length-Value (LV) encoded string into a JSON object. Can optionally include a <code>Key</code> / <code>Type</code> entry.";
24-
this.infoURL = "";
24+
this.infoURL = "https://wikipedia.org/wiki/KLV";
2525
this.inputType = "byteArray";
2626
this.outputType = "JSON";
2727
this.args = [
2828
{
2929
name: "Bytes in Key Value",
30-
type: "populateOption",
30+
type: "option",
3131
value: [
32-
{
33-
name: "0 Bytes (No Key)",
34-
value: "0"
35-
},
36-
{
37-
name: "1 Byte",
38-
value: "1"
39-
},
40-
{
41-
name: "2 Bytes",
42-
value: "2"
43-
},
44-
{
45-
name: "4 Bytes",
46-
value: "4"
47-
}
32+
"0 Bytes (No Key)",
33+
"1 Byte",
34+
"2 Bytes",
35+
"4 Bytes"
4836
]
4937
},
5038
{
5139
name: "Bytes in Length Value",
52-
type: "populateOption",
40+
type: "option",
5341
value: [
54-
{
55-
name: "1 Byte",
56-
value: "1"
57-
},
58-
{
59-
name: "2 Bytes",
60-
value: "2"
61-
},
62-
{
63-
name: "4 Bytes",
64-
value: "4"
65-
}
42+
"1 Byte",
43+
"2 Bytes",
44+
"4 Bytes"
6645
]
6746
},
6847
{
@@ -99,4 +78,4 @@ class FromLengthValue extends Operation {
9978

10079
}
10180

102-
export default FromLengthValue;
81+
export default LVDecode;

test/index.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import "./tests/operations/SetUnion";
6464
import "./tests/operations/SymmetricDifference";
6565
import "./tests/operations/TranslateDateTimeFormat";
6666
import "./tests/operations/Magic";
67-
import "./tests/operations/LengthValueDecoder";
67+
import "./tests/operations/LVDecode";
6868

6969
let allTestsPassing = true;
7070
const testStatusCounts = {

test/tests/operations/LVDecode.mjs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* LV Decoder tests.
3+
*
4+
* @author gchq77703 []
5+
* @copyright Crown Copyright 2018
6+
* @license Apache-2.0
7+
*/
8+
9+
import TestRegister from "../../TestRegister";
10+
11+
TestRegister.addTests([
12+
{
13+
name: "LVDecode: LengthValue",
14+
input: "\x05\x48\x6f\x75\x73\x65\x04\x72\x6f\x6f\x6d\x04\x64\x6f\x6f\x72",
15+
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]}]),
16+
recipeConfig: [
17+
{
18+
"op": "LV Decode",
19+
"args": ["0 Bytes (No Key)", "1 Byte", false]
20+
}
21+
]
22+
},
23+
{
24+
name: "LVDecode: LengthValue with BER",
25+
input: "\x05\x48\x6f\x75\x73\x65\x04\x72\x6f\x6f\x6d\x04\x64\x6f\x6f\x72",
26+
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]}]),
27+
recipeConfig: [
28+
{
29+
"op": "LV Decode",
30+
"args": ["0 Bytes (No Key)", "4 Bytes", false] // length value is patently wrong, should be ignored by BER.
31+
}
32+
]
33+
},
34+
{
35+
name: "LVDecode: KeyLengthValue",
36+
input: "\x04\x05\x48\x6f\x75\x73\x65\x05\x04\x72\x6f\x6f\x6d\x42\x04\x64\x6f\x6f\x72",
37+
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]}]),
38+
recipeConfig: [
39+
{
40+
"op": "LV Decode",
41+
"args": ["1 Byte", "1 Byte", false]
42+
}
43+
]
44+
},
45+
{
46+
name: "LVDecode: KeyLengthValue with BER",
47+
input: "\x04\x05\x48\x6f\x75\x73\x65\x05\x04\x72\x6f\x6f\x6d\x42\x04\x64\x6f\x6f\x72",
48+
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]}]),
49+
recipeConfig: [
50+
{
51+
"op": "LV Decode",
52+
"args": ["1 Byte", "4 Byte", true] // length value is patently wrong, should be ignored by BER.
53+
}
54+
]
55+
}
56+
]);

test/tests/operations/LengthValueDecoder.mjs

-23
This file was deleted.

0 commit comments

Comments
 (0)