@netkitty/codec 1.2.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/README.md +62 -10
  3. package/README.zh-CN.md +55 -9
  4. package/dist/Codec.d.ts +3 -2
  5. package/dist/Codec.js +109 -10
  6. package/dist/abstracts/BaseHeader.d.ts +54 -2
  7. package/dist/abstracts/BaseHeader.js +185 -43
  8. package/dist/errors/CodecSchemaValidateError.d.ts +34 -1
  9. package/dist/errors/CodecSchemaValidateError.js +26 -3
  10. package/dist/headers/ADSAMS.js +2 -0
  11. package/dist/headers/AH.js +4 -2
  12. package/dist/headers/AMQP.js +2 -1
  13. package/dist/headers/ARP.js +16 -10
  14. package/dist/headers/BACnetIP.js +1 -0
  15. package/dist/headers/BFD.d.ts +2 -1
  16. package/dist/headers/BFD.js +30 -4
  17. package/dist/headers/BGP.js +6 -1
  18. package/dist/headers/Babel.js +2 -1
  19. package/dist/headers/BitTorrent.d.ts +2 -0
  20. package/dist/headers/BitTorrent.js +4 -2
  21. package/dist/headers/C37118.d.ts +3 -2
  22. package/dist/headers/C37118.js +35 -15
  23. package/dist/headers/CAPWAP.js +1 -0
  24. package/dist/headers/CDP.d.ts +3 -3
  25. package/dist/headers/CDP.js +47 -11
  26. package/dist/headers/CMS.js +27 -12
  27. package/dist/headers/COTP.d.ts +2 -0
  28. package/dist/headers/COTP.js +8 -4
  29. package/dist/headers/CassandraCQL.js +1 -0
  30. package/dist/headers/CoAP.js +20 -2
  31. package/dist/headers/Codesys.js +1 -0
  32. package/dist/headers/Collectd.js +1 -1
  33. package/dist/headers/DCCP.d.ts +3 -2
  34. package/dist/headers/DCCP.js +61 -8
  35. package/dist/headers/DHCPFailover.js +1 -0
  36. package/dist/headers/DNP3.d.ts +5 -3
  37. package/dist/headers/DNP3.js +62 -7
  38. package/dist/headers/DNS.js +3 -3
  39. package/dist/headers/DTLS.js +1 -0
  40. package/dist/headers/Diameter.js +3 -2
  41. package/dist/headers/EAPOL.js +1 -1
  42. package/dist/headers/EIGRP.d.ts +3 -2
  43. package/dist/headers/EIGRP.js +32 -6
  44. package/dist/headers/ENIP.js +1 -0
  45. package/dist/headers/Elasticsearch.js +1 -0
  46. package/dist/headers/EtherCAT.js +1 -0
  47. package/dist/headers/EthernetII.js +7 -0
  48. package/dist/headers/FTP.js +6 -6
  49. package/dist/headers/Finger.js +3 -3
  50. package/dist/headers/FoundationFieldbusHSE.js +1 -0
  51. package/dist/headers/GELF.js +8 -1
  52. package/dist/headers/GENEVE.js +2 -1
  53. package/dist/headers/GLBP.js +1 -1
  54. package/dist/headers/GRE.js +1 -0
  55. package/dist/headers/GTPU.js +1 -0
  56. package/dist/headers/GTPv2C.js +2 -0
  57. package/dist/headers/GitProtocol.js +2 -2
  58. package/dist/headers/Goose.js +24 -12
  59. package/dist/headers/Gopher.js +6 -6
  60. package/dist/headers/HARTIP.js +1 -0
  61. package/dist/headers/HSR.js +3 -0
  62. package/dist/headers/HTTP.js +6 -6
  63. package/dist/headers/HTTP2.js +2 -0
  64. package/dist/headers/ICMP.js +3 -1
  65. package/dist/headers/ICMPv6.js +11 -16
  66. package/dist/headers/IEC104_I_Frame.js +215 -163
  67. package/dist/headers/IEC104_S_Frame.js +26 -3
  68. package/dist/headers/IEC104_U_Frame.js +33 -4
  69. package/dist/headers/IEC61850SampledValues.js +6 -5
  70. package/dist/headers/IGMP.d.ts +8 -7
  71. package/dist/headers/IGMP.js +58 -19
  72. package/dist/headers/IMAP.js +5 -5
  73. package/dist/headers/IPFIX.js +3 -2
  74. package/dist/headers/IPv4.js +41 -21
  75. package/dist/headers/IPv6.js +5 -1
  76. package/dist/headers/IPv6HopByHopOptions.js +15 -12
  77. package/dist/headers/IRC.js +4 -4
  78. package/dist/headers/ISAKMP.js +3 -1
  79. package/dist/headers/ISCSI.js +2 -0
  80. package/dist/headers/ISIS.js +2 -1
  81. package/dist/headers/ISOSession.d.ts +2 -0
  82. package/dist/headers/ISOSession.js +14 -10
  83. package/dist/headers/Ident.js +8 -8
  84. package/dist/headers/KNXnetIP.js +1 -0
  85. package/dist/headers/Kafka.js +1 -0
  86. package/dist/headers/Kerberos.js +2 -0
  87. package/dist/headers/L2TP.js +3 -2
  88. package/dist/headers/LACP.js +1 -1
  89. package/dist/headers/LDAP.js +3 -4
  90. package/dist/headers/LDP.js +1 -0
  91. package/dist/headers/LLC.d.ts +2 -0
  92. package/dist/headers/LLC.js +3 -0
  93. package/dist/headers/LPD.js +3 -3
  94. package/dist/headers/MGCP.js +7 -7
  95. package/dist/headers/MMS.d.ts +2 -0
  96. package/dist/headers/MMS.js +10 -6
  97. package/dist/headers/MQTT.js +1 -0
  98. package/dist/headers/MQTTSN.js +1 -0
  99. package/dist/headers/MarkerProtocol.js +1 -1
  100. package/dist/headers/Megaco.js +3 -3
  101. package/dist/headers/Memcached.js +3 -2
  102. package/dist/headers/ModbusTCP.js +1 -0
  103. package/dist/headers/ModbusUDP.js +1 -0
  104. package/dist/headers/MongoDB.js +1 -0
  105. package/dist/headers/MySQL.js +1 -0
  106. package/dist/headers/NATS.js +2 -2
  107. package/dist/headers/NBDS.js +1 -0
  108. package/dist/headers/NBSS.js +1 -0
  109. package/dist/headers/NFS.js +1 -0
  110. package/dist/headers/NHRP.d.ts +1 -1
  111. package/dist/headers/NHRP.js +30 -4
  112. package/dist/headers/NNTP.js +6 -6
  113. package/dist/headers/NetFlowV5.js +1 -0
  114. package/dist/headers/OLSR.js +2 -1
  115. package/dist/headers/OPCUA.js +1 -0
  116. package/dist/headers/OSPF.d.ts +3 -3
  117. package/dist/headers/OSPF.js +72 -7
  118. package/dist/headers/OpenFlow.js +1 -0
  119. package/dist/headers/OpenVPN.js +1 -0
  120. package/dist/headers/PCWorx.js +1 -0
  121. package/dist/headers/PIM.d.ts +3 -3
  122. package/dist/headers/PIM.js +55 -6
  123. package/dist/headers/POP3.js +5 -5
  124. package/dist/headers/PPPoEDiscovery.js +4 -1
  125. package/dist/headers/PPPoESession.js +1 -0
  126. package/dist/headers/PPTP.js +1 -0
  127. package/dist/headers/PTP.js +6 -1
  128. package/dist/headers/PostgreSQL.js +2 -0
  129. package/dist/headers/QUIC.js +2 -0
  130. package/dist/headers/RADIUS.js +1 -0
  131. package/dist/headers/RDP.d.ts +2 -0
  132. package/dist/headers/RDP.js +6 -1
  133. package/dist/headers/RFB.js +4 -4
  134. package/dist/headers/RGoose.js +8 -1
  135. package/dist/headers/RSVP.d.ts +3 -3
  136. package/dist/headers/RSVP.js +59 -44
  137. package/dist/headers/RTCP.js +2 -0
  138. package/dist/headers/RTP.js +2 -1
  139. package/dist/headers/RTPS.d.ts +2 -0
  140. package/dist/headers/RTPS.js +4 -1
  141. package/dist/headers/RTSP.js +7 -7
  142. package/dist/headers/RawData.js +1 -1
  143. package/dist/headers/Redis.js +4 -4
  144. package/dist/headers/Rlogin.js +5 -5
  145. package/dist/headers/Rsync.js +2 -2
  146. package/dist/headers/S7comm.d.ts +2 -0
  147. package/dist/headers/S7comm.js +5 -1
  148. package/dist/headers/SCTP.d.ts +2 -2
  149. package/dist/headers/SCTP.js +31 -7
  150. package/dist/headers/SFlow.js +2 -1
  151. package/dist/headers/SIP.js +6 -6
  152. package/dist/headers/SLMP.js +1 -0
  153. package/dist/headers/SLP.js +2 -0
  154. package/dist/headers/SLPv1.js +1 -0
  155. package/dist/headers/SMB1.js +1 -0
  156. package/dist/headers/SMB2.js +1 -0
  157. package/dist/headers/SMPP.js +1 -0
  158. package/dist/headers/SMTP.js +6 -6
  159. package/dist/headers/SNAP.js +18 -5
  160. package/dist/headers/SNMP.js +6 -6
  161. package/dist/headers/SOCKS4.js +11 -5
  162. package/dist/headers/SSDP.js +7 -7
  163. package/dist/headers/SSH.js +5 -4
  164. package/dist/headers/STOMP.js +5 -5
  165. package/dist/headers/STUN.js +3 -1
  166. package/dist/headers/SercosIII.d.ts +3 -2
  167. package/dist/headers/SercosIII.js +41 -5
  168. package/dist/headers/Skinny.js +1 -0
  169. package/dist/headers/StatsD.js +4 -4
  170. package/dist/headers/SunRPC.js +1 -0
  171. package/dist/headers/Syslog.js +2 -2
  172. package/dist/headers/TCP.js +31 -64
  173. package/dist/headers/TLS_Alert.js +42 -12
  174. package/dist/headers/TLS_ApplicationData.d.ts +3 -3
  175. package/dist/headers/TLS_ApplicationData.js +32 -8
  176. package/dist/headers/TLS_ChangeCipherSpec.d.ts +2 -2
  177. package/dist/headers/TLS_ChangeCipherSpec.js +33 -8
  178. package/dist/headers/TLS_Handshake.js +78 -30
  179. package/dist/headers/TLS_Heartbeat.d.ts +4 -3
  180. package/dist/headers/TLS_Heartbeat.js +50 -8
  181. package/dist/headers/TPKT.js +4 -2
  182. package/dist/headers/TacacsPlus.js +1 -0
  183. package/dist/headers/Telnet.js +2 -1
  184. package/dist/headers/Teredo.js +2 -2
  185. package/dist/headers/UDP.js +20 -56
  186. package/dist/headers/VLAN_802dot1Q.js +8 -0
  187. package/dist/headers/VRRP.d.ts +2 -1
  188. package/dist/headers/VRRP.js +45 -9
  189. package/dist/headers/WCCP.js +1 -0
  190. package/dist/headers/WHOIS.js +3 -3
  191. package/dist/headers/WSDiscovery.js +2 -2
  192. package/dist/headers/XMPP.js +3 -3
  193. package/dist/headers/Zabbix.js +1 -0
  194. package/dist/helper/Checksum.d.ts +15 -0
  195. package/dist/helper/Checksum.js +56 -0
  196. package/dist/helper/Crc.d.ts +18 -0
  197. package/dist/helper/Crc.js +58 -0
  198. package/dist/index.d.ts +3 -3
  199. package/dist/lib/SchemaValidator.d.ts +31 -0
  200. package/dist/lib/SchemaValidator.js +137 -0
  201. package/dist/schema/ProtocolFieldJSONSchema.d.ts +4 -1
  202. package/dist/schema/ProtocolJSONSchema.d.ts +1 -1
  203. package/dist/types/CodecErrorInfo.d.ts +11 -0
  204. package/dist/types/LayerGraph.d.ts +14 -1
  205. package/package.json +2 -2
@@ -68,22 +68,28 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
68
68
  this.SCHEMA = {
69
69
  type: 'object',
70
70
  properties: {
71
+ //Default 21 (alert): the content type match() requires.
71
72
  contentType: {
72
73
  type: 'integer',
73
74
  label: 'Content Type',
74
75
  minimum: 0,
75
76
  maximum: 65535,
77
+ default: 21,
76
78
  decode: () => {
77
79
  this.instance.contentType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
78
80
  },
79
81
  encode: () => {
80
- const contentTyppe = this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
82
+ const contentTyppe = this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
81
83
  this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(contentTyppe));
82
84
  }
83
85
  },
84
86
  version: {
85
87
  type: 'string',
86
88
  label: 'Legacy Version',
89
+ //Closed set: decode stores one of these names, or '0' for an unrecognized version.
90
+ enum: [...Object.values(TLSver), '0'],
91
+ //Default TLS 1.2 (0x0303, also the record version of TLS 1.3): match() requires a known version.
92
+ default: TLSver.TLS_1_2,
87
93
  minimum: 0,
88
94
  maximum: 65535,
89
95
  decode: () => {
@@ -121,7 +127,7 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
121
127
  }
122
128
  },
123
129
  encode: () => {
124
- const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
130
+ const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
125
131
  switch (version) {
126
132
  case TLSver.SSL_3_0:
127
133
  {
@@ -154,6 +160,9 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
154
160
  }
155
161
  break;
156
162
  default: {
163
+ //'0' is what decode stores for an unrecognized version; anything else is not a version.
164
+ if (`${version}` !== '0')
165
+ this.recordError(this.instance.version.getPath(), `Unknown TLS version '${version}', encoded as 0`, 'error');
157
166
  this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
158
167
  }
159
168
  }
@@ -161,15 +170,29 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
161
170
  },
162
171
  length: {
163
172
  type: 'integer',
164
- label: 'Legacy Version',
173
+ autoCalculated: true,
174
+ label: 'Length',
165
175
  minimum: 0,
166
- maximum: 255,
176
+ maximum: 65535,
167
177
  decode: () => {
168
178
  this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
169
179
  },
170
180
  encode: () => {
171
- const length = (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
172
- this.writeBytes(3, length);
181
+ if (!this.isLeftOut(this.instance.length)) {
182
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0)));
183
+ return;
184
+ }
185
+ //The record payload: every octet this layer writes after the 5-octet record header.
186
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
187
+ this.addPostSelfEncodeHandler(() => {
188
+ let length = this.length - 5;
189
+ if (length > 65535) {
190
+ this.recordError(this.instance.length.getPath(), 'Maximum value is 65535');
191
+ length = 65535;
192
+ }
193
+ this.instance.length.setValue(length);
194
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
195
+ });
173
196
  }
174
197
  },
175
198
  levelType: {
@@ -179,7 +202,7 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
179
202
  maximum: 255,
180
203
  decode: () => {
181
204
  this.instance.levelType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1)));
182
- const type = this.instance.levelType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
205
+ const type = this.instance.levelType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
183
206
  switch (type) {
184
207
  case 1:
185
208
  {
@@ -197,7 +220,7 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
197
220
  }
198
221
  },
199
222
  encode: () => {
200
- const type = this.instance.levelType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
223
+ const type = this.instance.levelType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
201
224
  switch (type) {
202
225
  case 'Warning':
203
226
  {
@@ -212,8 +235,11 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
212
235
  }
213
236
  break;
214
237
  default: {
238
+ //Not a known name: a numeric level (what decode stores for an unnamed one).
215
239
  const type1 = parseInt(type, 10);
216
- this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(type1));
240
+ if (!/^\d+$/.test(`${type}`) || type1 > 255)
241
+ this.recordError(this.instance.levelType.getPath(), `Unknown alert level '${type}', encoded as 0`, 'error');
242
+ this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(/^\d+$/.test(`${type}`) && type1 <= 255 ? type1 : 0));
217
243
  }
218
244
  }
219
245
  }
@@ -225,7 +251,7 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
225
251
  maximum: 255,
226
252
  decode: () => {
227
253
  this.instance.descriptionType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(6, 1)));
228
- const type = this.instance.descriptionType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
254
+ const type = this.instance.descriptionType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
229
255
  switch (type) {
230
256
  case 0:
231
257
  {
@@ -403,7 +429,7 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
403
429
  }
404
430
  },
405
431
  encode: () => {
406
- const type = this.instance.descriptionType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
432
+ const type = this.instance.descriptionType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
407
433
  switch (type) {
408
434
  case Description_type.code_0:
409
435
  {
@@ -610,8 +636,12 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
610
636
  }
611
637
  break;
612
638
  default: {
639
+ //Not a known name: a numeric description (what decode stores for an unnamed one).
613
640
  const type1 = parseInt(type, 10);
614
- const type2 = (0, NumberToBuffer_1.UInt8ToBuffer)(type1);
641
+ const known = /^\d+$/.test(`${type}`) && type1 <= 255;
642
+ if (!known)
643
+ this.recordError(this.instance.descriptionType.getPath(), `Unknown alert description '${type}', encoded as 0`, 'error');
644
+ const type2 = (0, NumberToBuffer_1.UInt8ToBuffer)(known ? type1 : 0);
615
645
  this.writeBytes(6, type2);
616
646
  }
617
647
  }
@@ -9,9 +9,9 @@ import { BaseHeader } from '../abstracts/BaseHeader';
9
9
  * `length` octets).
10
10
  *
11
11
  * The body is encrypted and opaque, so it is kept verbatim as `appData` hex (byte-perfect) and never
12
- * sub-decoded; the Length is honored as given. A well-formed record round-trips byte-for-byte. In the
13
- * heuristic chain (`heuristicFallback`), match() requires a Content Type of 0x17 and a recognized legacy
14
- * Version (0x0300-0x0304).
12
+ * sub-decoded; the Length is written as given, and left out it is the body's octet count. A well-formed
13
+ * record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
14
+ * Content Type of 0x17 and a recognized legacy Version (0x0300-0x0304).
15
15
  */
16
16
  export declare class TLS_ApplicationData extends BaseHeader {
17
17
  SCHEMA: ProtocolJSONSchema;
@@ -23,9 +23,9 @@ var TLSver;
23
23
  * `length` octets).
24
24
  *
25
25
  * The body is encrypted and opaque, so it is kept verbatim as `appData` hex (byte-perfect) and never
26
- * sub-decoded; the Length is honored as given. A well-formed record round-trips byte-for-byte. In the
27
- * heuristic chain (`heuristicFallback`), match() requires a Content Type of 0x17 and a recognized legacy
28
- * Version (0x0300-0x0304).
26
+ * sub-decoded; the Length is written as given, and left out it is the body's octet count. A well-formed
27
+ * record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
28
+ * Content Type of 0x17 and a recognized legacy Version (0x0300-0x0304).
29
29
  */
30
30
  class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
31
31
  constructor() {
@@ -33,22 +33,28 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
33
33
  this.SCHEMA = {
34
34
  type: 'object',
35
35
  properties: {
36
+ //Default 23 (application data): the content type match() requires.
36
37
  contentType: {
37
38
  type: 'integer',
38
39
  label: 'Content Type',
39
40
  minimum: 0,
40
41
  maximum: 255,
42
+ default: 23,
41
43
  decode: () => {
42
44
  this.instance.contentType.setValue((0, BufferToNumber_1.BufferToInt8)(this.readBytes(0, 1)));
43
45
  },
44
46
  encode: () => {
45
- const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
47
+ const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found')));
46
48
  this.writeBytes(0, contentType);
47
49
  }
48
50
  },
49
51
  version: {
50
52
  type: 'string',
51
53
  label: 'Legacy Version',
54
+ //Closed set: decode stores one of these names, or '0' for an unrecognized version.
55
+ enum: [...Object.values(TLSver), '0'],
56
+ //Default TLS 1.2 (0x0303, also the record version of TLS 1.3): match() requires a known version.
57
+ default: TLSver.TLS_1_2,
52
58
  minimum: 0,
53
59
  maximum: 65535,
54
60
  decode: () => {
@@ -85,7 +91,7 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
85
91
  }
86
92
  },
87
93
  encode: () => {
88
- const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
94
+ const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
89
95
  switch (version) {
90
96
  case TLSver.SSL_3_0:
91
97
  {
@@ -118,6 +124,9 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
118
124
  }
119
125
  break;
120
126
  default: {
127
+ //'0' is what decode stores for an unrecognized version; anything else is not a version.
128
+ if (`${version}` !== '0')
129
+ this.recordError(this.instance.version.getPath(), `Unknown TLS version '${version}', encoded as 0`, 'error');
121
130
  this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
122
131
  }
123
132
  }
@@ -125,6 +134,7 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
125
134
  },
126
135
  length: {
127
136
  type: 'integer',
137
+ autoCalculated: true,
128
138
  label: 'Length',
129
139
  minimum: 0,
130
140
  maximum: 65535,
@@ -132,8 +142,21 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
132
142
  this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
133
143
  },
134
144
  encode: () => {
135
- const length = (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
136
- this.writeBytes(3, length);
145
+ if (!this.isLeftOut(this.instance.length)) {
146
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0)));
147
+ return;
148
+ }
149
+ //The record payload: every octet this layer writes after the 5-octet record header.
150
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
151
+ this.addPostSelfEncodeHandler(() => {
152
+ let length = this.length - 5;
153
+ if (length > 65535) {
154
+ this.recordError(this.instance.length.getPath(), 'Maximum value is 65535');
155
+ length = 65535;
156
+ }
157
+ this.instance.length.setValue(length);
158
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
159
+ });
137
160
  }
138
161
  },
139
162
  appData: {
@@ -145,7 +168,8 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
145
168
  this.instance.appData.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(5, this.instance.length.getValue())));
146
169
  },
147
170
  encode: () => {
148
- const appData = (0, HexToBuffer_1.HexToBuffer)(this.instance.appData.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found')));
171
+ //Left out, the record carries no data (an empty record, Length 0 when computed).
172
+ const appData = (0, HexToBuffer_1.HexToBuffer)(this.instance.appData.getValue('', (nodePath) => this.recordError(nodePath, 'Not Found')));
149
173
  this.writeBytes(5, appData);
150
174
  }
151
175
  }
@@ -8,8 +8,8 @@ import { BaseHeader } from '../abstracts/BaseHeader';
8
8
  * else "0"), a 16-bit record Length (`length`, offset 3), and the message body
9
9
  * (`change_cipher_spec_message`, offset 5, `length` octets — canonically the single byte 0x01).
10
10
  *
11
- * The body is kept verbatim as hex (byte-perfect) and the Length is honored as given, so a well-formed
12
- * record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
11
+ * The body is kept verbatim as hex (byte-perfect) and the Length is written as given (left out, it is the
12
+ * body's octet count), so a well-formed record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
13
13
  * Content Type of 0x14 and a recognized legacy Version (0x0300-0x0304).
14
14
  */
15
15
  export declare class TLS_ChangeCipherSpec extends BaseHeader {
@@ -22,8 +22,8 @@ var TLSver;
22
22
  * else "0"), a 16-bit record Length (`length`, offset 3), and the message body
23
23
  * (`change_cipher_spec_message`, offset 5, `length` octets — canonically the single byte 0x01).
24
24
  *
25
- * The body is kept verbatim as hex (byte-perfect) and the Length is honored as given, so a well-formed
26
- * record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
25
+ * The body is kept verbatim as hex (byte-perfect) and the Length is written as given (left out, it is the
26
+ * body's octet count), so a well-formed record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
27
27
  * Content Type of 0x14 and a recognized legacy Version (0x0300-0x0304).
28
28
  */
29
29
  class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
@@ -32,22 +32,28 @@ class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
32
32
  this.SCHEMA = {
33
33
  type: 'object',
34
34
  properties: {
35
+ //Default 20 (change cipher spec): the content type match() requires.
35
36
  contentType: {
36
37
  type: 'integer',
37
38
  label: 'Content Type',
38
39
  minimum: 0,
39
40
  maximum: 255,
41
+ default: 20,
40
42
  decode: () => {
41
43
  this.instance.contentType.setValue((0, BufferToNumber_1.BufferToInt8)(this.readBytes(0, 1)));
42
44
  },
43
45
  encode: () => {
44
- const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
46
+ const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found')));
45
47
  this.writeBytes(0, contentType);
46
48
  }
47
49
  },
48
50
  version: {
49
51
  type: 'string',
50
52
  label: 'Legacy Version',
53
+ //Closed set: decode stores one of these names, or '0' for an unrecognized version.
54
+ enum: [...Object.values(TLSver), '0'],
55
+ //Default TLS 1.2 (0x0303, also the record version of TLS 1.3): match() requires a known version.
56
+ default: TLSver.TLS_1_2,
51
57
  minimum: 0,
52
58
  maximum: 65535,
53
59
  decode: () => {
@@ -84,7 +90,7 @@ class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
84
90
  }
85
91
  },
86
92
  encode: () => {
87
- const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
93
+ const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
88
94
  switch (version) {
89
95
  case TLSver.SSL_3_0:
90
96
  {
@@ -117,6 +123,9 @@ class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
117
123
  }
118
124
  break;
119
125
  default: {
126
+ //'0' is what decode stores for an unrecognized version; anything else is not a version.
127
+ if (`${version}` !== '0')
128
+ this.recordError(this.instance.version.getPath(), `Unknown TLS version '${version}', encoded as 0`, 'error');
120
129
  this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
121
130
  }
122
131
  }
@@ -124,6 +133,7 @@ class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
124
133
  },
125
134
  length: {
126
135
  type: 'integer',
136
+ autoCalculated: true,
127
137
  label: 'Length',
128
138
  minimum: 0,
129
139
  maximum: 65535,
@@ -131,19 +141,34 @@ class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
131
141
  this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
132
142
  },
133
143
  encode: () => {
134
- const length = (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
135
- this.writeBytes(3, length);
144
+ if (!this.isLeftOut(this.instance.length)) {
145
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0)));
146
+ return;
147
+ }
148
+ //The record payload: every octet this layer writes after the 5-octet record header.
149
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
150
+ this.addPostSelfEncodeHandler(() => {
151
+ let length = this.length - 5;
152
+ if (length > 65535) {
153
+ this.recordError(this.instance.length.getPath(), 'Maximum value is 65535');
154
+ length = 65535;
155
+ }
156
+ this.instance.length.setValue(length);
157
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
158
+ });
136
159
  }
137
160
  },
138
161
  change_cipher_spec_message: {
139
162
  type: 'string',
140
163
  label: 'Change Cipher Spec Message',
164
+ //Default 0x01: the one-octet change_cipher_spec message (RFC 5246 section 7.1).
165
+ default: '01',
141
166
  decode: () => {
142
- const length = this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found'));
167
+ const length = this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
143
168
  this.instance.change_cipher_spec_message.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(5, length)));
144
169
  },
145
170
  encode: () => {
146
- const message = (0, HexToBuffer_1.HexToBuffer)(this.instance.change_cipher_spec_message.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found')));
171
+ const message = (0, HexToBuffer_1.HexToBuffer)(this.instance.change_cipher_spec_message.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found')));
147
172
  this.writeBytes(5, message);
148
173
  }
149
174
  }
@@ -35,22 +35,28 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
35
35
  this.SCHEMA = {
36
36
  type: 'object',
37
37
  properties: {
38
+ //Default 22 (handshake): the content type match() requires.
38
39
  contentType: {
39
40
  type: 'integer',
40
41
  label: 'Content Type',
41
42
  minimum: 0,
42
43
  maximum: 255,
44
+ default: 22,
43
45
  decode: () => {
44
46
  this.instance.contentType.setValue((0, BufferToNumber_1.BufferToInt8)(this.readBytes(0, 1)));
45
47
  },
46
48
  encode: () => {
47
- const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
49
+ const contentType = (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found')));
48
50
  this.writeBytes(0, contentType);
49
51
  }
50
52
  },
51
53
  version: {
52
54
  type: 'string',
53
55
  label: 'Legacy Version',
56
+ //Closed set: decode stores one of these names, or '0' for an unrecognized version.
57
+ enum: [...Object.values(TLSver), '0'],
58
+ //Default TLS 1.2 (0x0303, also the record version of TLS 1.3): match() requires a known version.
59
+ default: TLSver.TLS_1_2,
54
60
  minimum: 0,
55
61
  maximum: 65535,
56
62
  decode: () => {
@@ -87,7 +93,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
87
93
  }
88
94
  },
89
95
  encode: () => {
90
- const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'));
96
+ const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
91
97
  switch (version) {
92
98
  case TLSver.SSL_3_0:
93
99
  {
@@ -120,6 +126,9 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
120
126
  }
121
127
  break;
122
128
  default: {
129
+ //'0' is what decode stores for an unrecognized version; anything else is not a version.
130
+ if (`${version}` !== '0')
131
+ this.recordError(this.instance.version.getPath(), `Unknown TLS version '${version}', encoded as 0`, 'error');
123
132
  this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
124
133
  }
125
134
  }
@@ -127,6 +136,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
127
136
  },
128
137
  length: {
129
138
  type: 'integer',
139
+ autoCalculated: true,
130
140
  label: 'Length',
131
141
  minimum: 0,
132
142
  maximum: 65535,
@@ -134,8 +144,21 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
134
144
  this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
135
145
  },
136
146
  encode: () => {
137
- const length = (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
138
- this.writeBytes(3, length);
147
+ if (!this.isLeftOut(this.instance.length)) {
148
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(this.instance.length.getValue(0)));
149
+ return;
150
+ }
151
+ //The record payload: every octet this layer writes after the 5-octet record header.
152
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
153
+ this.addPostSelfEncodeHandler(() => {
154
+ let length = this.length - 5;
155
+ if (length > 65535) {
156
+ this.recordError(this.instance.length.getPath(), 'Maximum value is 65535');
157
+ length = 65535;
158
+ }
159
+ this.instance.length.setValue(length);
160
+ this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
161
+ });
139
162
  }
140
163
  },
141
164
  handshakeType: {
@@ -287,25 +310,44 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
287
310
  }
288
311
  break;
289
312
  default: {
313
+ //Not a known name: a numeric type (what decode stores for an unnamed one).
290
314
  const handshakeType1 = parseInt(handshakeType);
291
- this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(handshakeType1));
315
+ const known = /^\d+$/.test(`${handshakeType}`) && handshakeType1 <= 255;
316
+ if (!known)
317
+ this.recordError(this.instance.handshakeType.getPath(), `Unknown handshake type '${handshakeType}', encoded as 0`, 'error');
318
+ this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(known ? handshakeType1 : 0));
292
319
  }
293
320
  }
294
321
  }
295
322
  },
323
+ //The handshake message length. A fragment's may exceed the body this record carries (the
324
+ //message continues in later records), so it is written as given; left out, it is the body
325
+ //this layer writes after the 4-octet handshake header.
296
326
  handshakeLength: {
297
327
  type: 'integer',
328
+ autoCalculated: true,
298
329
  label: 'Length',
299
330
  minimum: 0,
300
- maximum: 1118481,
331
+ maximum: 16777215,
301
332
  decode: () => {
302
333
  this.instance.handshakeLength.setValue((0, BufferToNumber_1.BufferToUInt32)(this.readBytes(6, 3)));
303
334
  },
304
335
  encode: () => {
305
- const length1 = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
306
- const length2 = length1.toString(16).padStart(6, '0');
307
- const length3 = (0, HexToBuffer_1.HexToBuffer)(length2);
308
- this.writeBytes(6, length3);
336
+ const write = (length) => this.writeBytes(6, (0, HexToBuffer_1.HexToBuffer)(length.toString(16).padStart(6, '0')));
337
+ if (!this.isLeftOut(this.instance.handshakeLength)) {
338
+ write(this.instance.handshakeLength.getValue(0));
339
+ return;
340
+ }
341
+ write(0);
342
+ this.addPostSelfEncodeHandler(() => {
343
+ let length = this.length - 9;
344
+ if (length > 16777215) {
345
+ this.recordError(this.instance.handshakeLength.getPath(), 'Maximum value is 16777215');
346
+ length = 16777215;
347
+ }
348
+ this.instance.handshakeLength.setValue(length);
349
+ write(length);
350
+ });
309
351
  }
310
352
  },
311
353
  messagedata: {
@@ -326,7 +368,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
326
368
  type: 'object',
327
369
  properties: {
328
370
  type: { type: 'string', label: 'Type' },
329
- name: { type: 'string', label: 'Name' },
371
+ name: { type: 'string', label: 'Name', readOnly: true },
330
372
  //Present only for extensions we cannot structure (unknown type or
331
373
  //malformed): the raw extension data, kept as hex so it round-trips.
332
374
  data: { type: 'string', contentEncoding: 'hex', label: 'Data' },
@@ -356,7 +398,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
356
398
  raw: { type: 'string', contentEncoding: 'hex', label: 'Unparsed Body' }
357
399
  },
358
400
  decode: () => {
359
- const handshakeLength = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not found')));
401
+ const handshakeLength = (this.instance.handshakeLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found')));
360
402
  //handshakeLength describes the whole (possibly reassembled) message, which may
361
403
  //span multiple TLS records. The body carried by THIS record is bounded by the
362
404
  //record-layer length minus the 4-byte handshake header (type + 3-byte length);
@@ -391,7 +433,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
391
433
  }
392
434
  const handshakeType = this.instance.handshakeType.getValue();
393
435
  const parts = [];
394
- parts.push(this.tlsVersionStringToBuffer(md.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not found'))));
436
+ parts.push(this.tlsVersionStringToBuffer(md.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'))));
395
437
  parts.push((0, HexToBuffer_1.HexToBuffer)(md.random.getValue('')));
396
438
  const sessionId = (0, HexToBuffer_1.HexToBuffer)(md.sessionId.getValue(''));
397
439
  parts.push((0, NumberToBuffer_1.UInt8ToBuffer)(sessionId.length), sessionId);
@@ -407,7 +449,12 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
407
449
  }
408
450
  if (!md.extensions.isUndefined()) {
409
451
  const extensionList = md.extensions.getValue([]);
410
- const extensions = Buffer.concat(extensionList.map((extension) => {
452
+ const extensions = Buffer.concat(extensionList.map((extension, index) => {
453
+ //An extension without its 2-byte type cannot be framed: skip it, reported.
454
+ if (typeof extension.type !== 'string' || !extension.type) {
455
+ this.recordError(`${md.extensions.getPath()}[${index}].type`, 'Not Found, extension ignored');
456
+ return Buffer.alloc(0);
457
+ }
411
458
  //Structurally decoded extensions carry their specific fields (no `data`);
412
459
  //rebuild those from the fields. Hex-preserved extensions carry `data`.
413
460
  const data = extension.data !== undefined ? (0, HexToBuffer_1.HexToBuffer)(extension.data) : this.encodeExtensionData(extension, handshakeType);
@@ -791,9 +838,9 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
791
838
  encodeExtensionData(extension, handshakeType) {
792
839
  switch (extension.type.toLowerCase()) {
793
840
  case '0000': { //server_name
794
- const entries = Buffer.concat(extension.serverNames.map((serverName) => {
795
- const host = Buffer.from(serverName.hostName, 'ascii');
796
- const nameType = serverName.nameType === 'host_name' ? 0 : parseInt(serverName.nameType);
841
+ const entries = Buffer.concat((extension.serverNames ?? []).map((serverName) => {
842
+ const host = Buffer.from(serverName.hostName ?? '', 'ascii');
843
+ const nameType = serverName.nameType === undefined || serverName.nameType === 'host_name' ? 0 : parseInt(serverName.nameType) || 0;
797
844
  return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(nameType), (0, NumberToBuffer_1.UInt16ToBuffer)(host.length), host]);
798
845
  }));
799
846
  if (entries.length === 0)
@@ -801,38 +848,39 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
801
848
  return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(entries.length), entries]);
802
849
  }
803
850
  case '000a':
804
- return this.encodeCodeList16(extension.groups);
851
+ return this.encodeCodeList16(extension.groups ?? []);
805
852
  case '000d':
806
- return this.encodeCodeList16(extension.signatureAlgorithms);
853
+ return this.encodeCodeList16(extension.signatureAlgorithms ?? []);
807
854
  case '000b': {
808
- const list = Buffer.concat(extension.ecPointFormats.map((format) => (0, HexToBuffer_1.HexToBuffer)(format)));
855
+ const list = Buffer.concat((extension.ecPointFormats ?? []).map((format) => (0, HexToBuffer_1.HexToBuffer)(format)));
809
856
  return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(list.length), list]);
810
857
  }
811
858
  case '002d': {
812
- const list = Buffer.concat(extension.modes.map((mode) => (0, HexToBuffer_1.HexToBuffer)(mode)));
859
+ const list = Buffer.concat((extension.modes ?? []).map((mode) => (0, HexToBuffer_1.HexToBuffer)(mode)));
813
860
  return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(list.length), list]);
814
861
  }
815
862
  case '0010': {
816
- const entries = Buffer.concat(extension.protocols.map((protocol) => {
817
- const bytes = Buffer.from(protocol, 'ascii');
863
+ const entries = Buffer.concat((extension.protocols ?? []).map((protocol) => {
864
+ const bytes = Buffer.from(protocol ?? '', 'ascii');
818
865
  return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(bytes.length), bytes]);
819
866
  }));
820
867
  return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(entries.length), entries]);
821
868
  }
822
869
  case '002b': {
823
870
  if (handshakeType === HandshakeType.Handshake_3)
824
- return this.tlsVersionStringToBuffer(extension.selectedVersion);
825
- const list = Buffer.concat(extension.versions.map((version) => this.tlsVersionStringToBuffer(version)));
871
+ return this.tlsVersionStringToBuffer(extension.selectedVersion ?? '0');
872
+ const list = Buffer.concat((extension.versions ?? []).map((version) => this.tlsVersionStringToBuffer(version)));
826
873
  return Buffer.concat([(0, NumberToBuffer_1.UInt8ToBuffer)(list.length), list]);
827
874
  }
828
875
  case '0033': {
829
876
  if (handshakeType === HandshakeType.Handshake_3) {
830
- const key = (0, HexToBuffer_1.HexToBuffer)(extension.keyShare.keyExchange);
831
- return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(extension.keyShare.group), (0, NumberToBuffer_1.UInt16ToBuffer)(key.length), key]);
877
+ const keyShare = extension.keyShare ?? {};
878
+ const key = (0, HexToBuffer_1.HexToBuffer)(keyShare.keyExchange ?? '');
879
+ return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(keyShare.group ?? '0000'), (0, NumberToBuffer_1.UInt16ToBuffer)(key.length), key]);
832
880
  }
833
- const entries = Buffer.concat(extension.keyShares.map((keyShare) => {
834
- const key = (0, HexToBuffer_1.HexToBuffer)(keyShare.keyExchange);
835
- return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(keyShare.group), (0, NumberToBuffer_1.UInt16ToBuffer)(key.length), key]);
881
+ const entries = Buffer.concat((extension.keyShares ?? []).map((keyShare) => {
882
+ const key = (0, HexToBuffer_1.HexToBuffer)(keyShare.keyExchange ?? '');
883
+ return Buffer.concat([(0, HexToBuffer_1.HexToBuffer)(keyShare.group ?? '0000'), (0, NumberToBuffer_1.UInt16ToBuffer)(key.length), key]);
836
884
  }));
837
885
  return Buffer.concat([(0, NumberToBuffer_1.UInt16ToBuffer)(entries.length), entries]);
838
886
  }
@@ -12,9 +12,10 @@ import { BaseHeader } from '../abstracts/BaseHeader';
12
12
  *
13
13
  * Per RFC 6520 §4 the padding is at least 16 octets and fills the record after the type and payload, so its
14
14
  * length is derived as recordLength - 3 - payloadLength and preserved for a byte-exact re-encode. The
15
- * payload and padding are kept verbatim and lengths are honored as given, so a well-formed record
16
- * round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a Content Type
17
- * of 0x18 and a recognized legacy Version (0x0300-0x0304).
15
+ * payload and padding are kept verbatim and lengths are written as given (left out, the record Length is
16
+ * the octets after the record header and the Payload Length the payload's octet count), so a well-formed
17
+ * record round-trips byte-for-byte. In the heuristic chain (`heuristicFallback`), match() requires a
18
+ * Content Type of 0x18 and a recognized legacy Version (0x0300-0x0304).
18
19
  */
19
20
  export declare class TLS_Heartbeat extends BaseHeader {
20
21
  SCHEMA: ProtocolJSONSchema;