LVDecode.mjs 2.2 KB

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