|
| 1 | +/** |
| 2 | + * Parse TLV 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: "Parse TLV: 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]}], null, 4), |
| 16 | + recipeConfig: [ |
| 17 | + { |
| 18 | + "op": "Parse TLV", |
| 19 | + "args": [0, 1, false] |
| 20 | + } |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "Parse TLV: 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]}], null, 4), |
| 27 | + recipeConfig: [ |
| 28 | + { |
| 29 | + "op": "Parse TLV", |
| 30 | + "args": [0, 4, true] // length value is patently wrong, should be ignored by BER. |
| 31 | + } |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "Parse TLV: 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]}], null, 4), |
| 38 | + recipeConfig: [ |
| 39 | + { |
| 40 | + "op": "Parse TLV", |
| 41 | + "args": [1, 1, false] |
| 42 | + } |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "Parse TLV: 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]}], null, 4), |
| 49 | + recipeConfig: [ |
| 50 | + { |
| 51 | + "op": "Parse TLV", |
| 52 | + "args": [1, 4, true] // length value is patently wrong, should be ignored by BER. |
| 53 | + } |
| 54 | + ] |
| 55 | + } |
| 56 | +]); |
0 commit comments