fix TLV Parser BER long-form length parsing (#2289)

This commit is contained in:
Willi Ballenthin
2026-06-20 08:59:30 +01:00
committed by GitHub
parent 9a8a279b82
commit 0a0d95bcbd
2 changed files with 57 additions and 7 deletions
+41
View File
@@ -52,5 +52,46 @@ TestRegister.addTests([
"args": [1, 4, true] // length value is patently wrong, should be ignored by BER.
}
]
},
{
name: "Parse TLV: BER long-form length (two-byte length encoding)",
input: "\x01\x82\x01\x00" + "A".repeat(256) + "\x02\x03\x41\x42\x43",
expectedOutput: JSON.stringify([
{"key": [1], "length": 256, "value": Array(256).fill(65)},
{"key": [2], "length": 3, "value": [65, 66, 67]}
], null, 4),
recipeConfig: [
{
"op": "Parse TLV",
"args": [1, 1, true]
}
]
},
{
name: "Parse TLV: BER long-form length (one-byte length encoding)",
input: "\x01\x81\x80" + "B".repeat(128),
expectedOutput: JSON.stringify([
{"key": [1], "length": 128, "value": Array(128).fill(66)}
], null, 4),
recipeConfig: [
{
"op": "Parse TLV",
"args": [1, 1, true]
}
]
},
{
name: "Parse TLV: BER multiple entries with mixed short and long-form lengths",
input: "\x01\x05\x48\x65\x6c\x6c\x6f\x02\x81\x05\x57\x6f\x72\x6c\x64",
expectedOutput: JSON.stringify([
{"key": [1], "length": 5, "value": [72, 101, 108, 108, 111]},
{"key": [2], "length": 5, "value": [87, 111, 114, 108, 100]}
], null, 4),
recipeConfig: [
{
"op": "Parse TLV",
"args": [1, 1, true]
}
]
}
]);