pypcapkit 1.6.2__pp312-none-any.whl

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 (770) hide show
  1. pcapkit/__init__.py +107 -0
  2. pcapkit/__main__.py +158 -0
  3. pcapkit/all.py +168 -0
  4. pcapkit/const/__init__.py +143 -0
  5. pcapkit/const/arp/__init__.py +35 -0
  6. pcapkit/const/arp/hardware.py +195 -0
  7. pcapkit/const/arp/operation.py +145 -0
  8. pcapkit/const/dccp/__init__.py +58 -0
  9. pcapkit/const/dccp/ack_vector_state.py +73 -0
  10. pcapkit/const/dccp/drop_code.py +79 -0
  11. pcapkit/const/dccp/feature.py +106 -0
  12. pcapkit/const/dccp/option.py +133 -0
  13. pcapkit/const/dccp/packet_type.py +103 -0
  14. pcapkit/const/dccp/reset_code.py +115 -0
  15. pcapkit/const/esp/__init__.py +49 -0
  16. pcapkit/const/esp/cipher.py +265 -0
  17. pcapkit/const/esp/integrity.py +154 -0
  18. pcapkit/const/ftp/__init__.py +35 -0
  19. pcapkit/const/ftp/command.py +659 -0
  20. pcapkit/const/ftp/return_code.py +409 -0
  21. pcapkit/const/hip/__init__.py +121 -0
  22. pcapkit/const/hip/certificate.py +91 -0
  23. pcapkit/const/hip/cipher.py +79 -0
  24. pcapkit/const/hip/di.py +73 -0
  25. pcapkit/const/hip/ecdsa_curve.py +73 -0
  26. pcapkit/const/hip/ecdsa_low_curve.py +70 -0
  27. pcapkit/const/hip/eddsa_curve.py +79 -0
  28. pcapkit/const/hip/esp_transform_suite.py +112 -0
  29. pcapkit/const/hip/group.py +100 -0
  30. pcapkit/const/hip/hi_algorithm.py +100 -0
  31. pcapkit/const/hip/hit_suite.py +82 -0
  32. pcapkit/const/hip/nat_traversal.py +76 -0
  33. pcapkit/const/hip/notify_message.py +214 -0
  34. pcapkit/const/hip/packet.py +103 -0
  35. pcapkit/const/hip/parameter.py +391 -0
  36. pcapkit/const/hip/registration.py +82 -0
  37. pcapkit/const/hip/registration_failure.py +98 -0
  38. pcapkit/const/hip/suite.py +85 -0
  39. pcapkit/const/hip/transport.py +73 -0
  40. pcapkit/const/http/__init__.py +52 -0
  41. pcapkit/const/http/error_code.py +108 -0
  42. pcapkit/const/http/frame.py +109 -0
  43. pcapkit/const/http/method.py +329 -0
  44. pcapkit/const/http/setting.py +110 -0
  45. pcapkit/const/http/status_code.py +347 -0
  46. pcapkit/const/icmp/__init__.py +52 -0
  47. pcapkit/const/icmp/destination_unreachable_code.py +111 -0
  48. pcapkit/const/icmp/parameter_problem_code.py +70 -0
  49. pcapkit/const/icmp/time_exceeded_code.py +67 -0
  50. pcapkit/const/icmp/type.py +179 -0
  51. pcapkit/const/icmpv6/__init__.py +52 -0
  52. pcapkit/const/icmpv6/destination_unreachable_code.py +91 -0
  53. pcapkit/const/icmpv6/parameter_problem_code.py +94 -0
  54. pcapkit/const/icmpv6/time_exceeded_code.py +67 -0
  55. pcapkit/const/icmpv6/type.py +209 -0
  56. pcapkit/const/ieee802_11/__init__.py +52 -0
  57. pcapkit/const/ieee802_11/control_subtype.py +106 -0
  58. pcapkit/const/ieee802_11/data_subtype.py +97 -0
  59. pcapkit/const/ieee802_11/extension_subtype.py +70 -0
  60. pcapkit/const/ieee802_11/management_subtype.py +109 -0
  61. pcapkit/const/ieee802_11/type.py +73 -0
  62. pcapkit/const/igmp/__init__.py +37 -0
  63. pcapkit/const/igmp/record_type.py +73 -0
  64. pcapkit/const/igmp/type.py +112 -0
  65. pcapkit/const/ipv4/__init__.py +79 -0
  66. pcapkit/const/ipv4/classification_level.py +77 -0
  67. pcapkit/const/ipv4/option_class.py +69 -0
  68. pcapkit/const/ipv4/option_number.py +151 -0
  69. pcapkit/const/ipv4/protection_authority.py +77 -0
  70. pcapkit/const/ipv4/qs_function.py +65 -0
  71. pcapkit/const/ipv4/router_alert.py +268 -0
  72. pcapkit/const/ipv4/tos_del.py +65 -0
  73. pcapkit/const/ipv4/tos_ecn.py +69 -0
  74. pcapkit/const/ipv4/tos_pre.py +77 -0
  75. pcapkit/const/ipv4/tos_rel.py +65 -0
  76. pcapkit/const/ipv4/tos_thr.py +65 -0
  77. pcapkit/const/ipv4/ts_flag.py +67 -0
  78. pcapkit/const/ipv6/__init__.py +70 -0
  79. pcapkit/const/ipv6/extension_header.py +86 -0
  80. pcapkit/const/ipv6/option.py +151 -0
  81. pcapkit/const/ipv6/option_action.py +69 -0
  82. pcapkit/const/ipv6/qs_function.py +65 -0
  83. pcapkit/const/ipv6/router_alert.py +280 -0
  84. pcapkit/const/ipv6/routing.py +94 -0
  85. pcapkit/const/ipv6/seed_id.py +69 -0
  86. pcapkit/const/ipv6/smf_dpd_mode.py +65 -0
  87. pcapkit/const/ipv6/tagger_id.py +76 -0
  88. pcapkit/const/ipx/__init__.py +37 -0
  89. pcapkit/const/ipx/packet.py +86 -0
  90. pcapkit/const/ipx/socket.py +121 -0
  91. pcapkit/const/l2tp/__init__.py +30 -0
  92. pcapkit/const/l2tp/type.py +65 -0
  93. pcapkit/const/linux/__init__.py +28 -0
  94. pcapkit/const/linux/arphrd.py +91 -0
  95. pcapkit/const/mh/__init__.py +259 -0
  96. pcapkit/const/mh/access_type.py +106 -0
  97. pcapkit/const/mh/ack_status_code.py +85 -0
  98. pcapkit/const/mh/ani_suboption.py +88 -0
  99. pcapkit/const/mh/auth_subtype.py +67 -0
  100. pcapkit/const/mh/binding_ack_flag.py +82 -0
  101. pcapkit/const/mh/binding_error.py +65 -0
  102. pcapkit/const/mh/binding_revocation.py +73 -0
  103. pcapkit/const/mh/binding_update_flag.py +97 -0
  104. pcapkit/const/mh/cga_extension.py +80 -0
  105. pcapkit/const/mh/cga_sec.py +71 -0
  106. pcapkit/const/mh/cga_type.py +82 -0
  107. pcapkit/const/mh/dhcp_support_mode.py +67 -0
  108. pcapkit/const/mh/dns_status_code.py +79 -0
  109. pcapkit/const/mh/dsmip6_tls_packet.py +76 -0
  110. pcapkit/const/mh/dsmipv6_home_address.py +88 -0
  111. pcapkit/const/mh/enumerating_algorithm.py +70 -0
  112. pcapkit/const/mh/fb_ack_status.py +76 -0
  113. pcapkit/const/mh/fb_action.py +85 -0
  114. pcapkit/const/mh/fb_indication_trigger.py +79 -0
  115. pcapkit/const/mh/fb_type.py +73 -0
  116. pcapkit/const/mh/flow_id_status.py +91 -0
  117. pcapkit/const/mh/flow_id_suboption.py +85 -0
  118. pcapkit/const/mh/handoff_type.py +85 -0
  119. pcapkit/const/mh/handover_ack_flag.py +70 -0
  120. pcapkit/const/mh/handover_ack_status.py +106 -0
  121. pcapkit/const/mh/handover_initiate_flag.py +73 -0
  122. pcapkit/const/mh/handover_initiate_status.py +76 -0
  123. pcapkit/const/mh/home_address_reply.py +85 -0
  124. pcapkit/const/mh/lla_code.py +77 -0
  125. pcapkit/const/mh/lma_mag_suboption.py +73 -0
  126. pcapkit/const/mh/mn_group_id.py +73 -0
  127. pcapkit/const/mh/mn_id_subtype.py +91 -0
  128. pcapkit/const/mh/operator_id.py +77 -0
  129. pcapkit/const/mh/option.py +274 -0
  130. pcapkit/const/mh/packet.py +133 -0
  131. pcapkit/const/mh/qos_attribute.py +103 -0
  132. pcapkit/const/mh/revocation_status_code.py +97 -0
  133. pcapkit/const/mh/revocation_trigger.py +100 -0
  134. pcapkit/const/mh/status_code.py +246 -0
  135. pcapkit/const/mh/traffic_selector.py +76 -0
  136. pcapkit/const/mh/upa_status.py +85 -0
  137. pcapkit/const/mh/upn_reason.py +94 -0
  138. pcapkit/const/ngap/__init__.py +44 -0
  139. pcapkit/const/ngap/procedure_code.py +223 -0
  140. pcapkit/const/ngap/protocol_ie.py +937 -0
  141. pcapkit/const/ospf/__init__.py +37 -0
  142. pcapkit/const/ospf/authentication.py +79 -0
  143. pcapkit/const/ospf/packet.py +85 -0
  144. pcapkit/const/pcapng/__init__.py +71 -0
  145. pcapkit/const/pcapng/block_type.py +166 -0
  146. pcapkit/const/pcapng/filter_type.py +62 -0
  147. pcapkit/const/pcapng/hash_algorithm.py +73 -0
  148. pcapkit/const/pcapng/option_type.py +422 -0
  149. pcapkit/const/pcapng/record_type.py +70 -0
  150. pcapkit/const/pcapng/secrets_type.py +69 -0
  151. pcapkit/const/pcapng/tls_key_label.py +89 -0
  152. pcapkit/const/pcapng/verdict_type.py +67 -0
  153. pcapkit/const/radiotap/__init__.py +116 -0
  154. pcapkit/const/radiotap/ampdu_flags.py +85 -0
  155. pcapkit/const/radiotap/channel_flags.py +94 -0
  156. pcapkit/const/radiotap/eht_known.py +124 -0
  157. pcapkit/const/radiotap/field_type.py +165 -0
  158. pcapkit/const/radiotap/flags.py +85 -0
  159. pcapkit/const/radiotap/he_data1_known.py +103 -0
  160. pcapkit/const/radiotap/he_data2_known.py +88 -0
  161. pcapkit/const/radiotap/he_mu_flags1_known.py +85 -0
  162. pcapkit/const/radiotap/he_mu_flags2_known.py +67 -0
  163. pcapkit/const/radiotap/he_mu_other_user_known.py +85 -0
  164. pcapkit/const/radiotap/lsig_data1.py +67 -0
  165. pcapkit/const/radiotap/mcs_known.py +85 -0
  166. pcapkit/const/radiotap/rx_flags.py +64 -0
  167. pcapkit/const/radiotap/s1g_known.py +85 -0
  168. pcapkit/const/radiotap/timestamp_flags.py +67 -0
  169. pcapkit/const/radiotap/tx_flags.py +82 -0
  170. pcapkit/const/radiotap/usig_common_known.py +85 -0
  171. pcapkit/const/radiotap/vht_coding.py +73 -0
  172. pcapkit/const/radiotap/vht_flags.py +84 -0
  173. pcapkit/const/radiotap/vht_known.py +90 -0
  174. pcapkit/const/reg/__init__.py +54 -0
  175. pcapkit/const/reg/apptype/__init__.py +164 -0
  176. pcapkit/const/reg/apptype/apptype.py +5233 -0
  177. pcapkit/const/reg/apptype/dccp.py +112 -0
  178. pcapkit/const/reg/apptype/sctp.py +432 -0
  179. pcapkit/const/reg/apptype/tcp.py +25154 -0
  180. pcapkit/const/reg/apptype/udp.py +24563 -0
  181. pcapkit/const/reg/ethertype.py +740 -0
  182. pcapkit/const/reg/linktype.py +811 -0
  183. pcapkit/const/reg/transtype.py +552 -0
  184. pcapkit/const/sctp/__init__.py +49 -0
  185. pcapkit/const/sctp/cause_code.py +146 -0
  186. pcapkit/const/sctp/chunk.py +164 -0
  187. pcapkit/const/sctp/parameter.py +170 -0
  188. pcapkit/const/sctp/payload_protocol_identifier.py +325 -0
  189. pcapkit/const/sslv2/__init__.py +37 -0
  190. pcapkit/const/sslv2/handshake_type.py +88 -0
  191. pcapkit/const/sslv2/version.py +64 -0
  192. pcapkit/const/tcp/__init__.py +47 -0
  193. pcapkit/const/tcp/checksum.py +69 -0
  194. pcapkit/const/tcp/flags.py +96 -0
  195. pcapkit/const/tcp/mp_tcp_option.py +95 -0
  196. pcapkit/const/tcp/option.py +210 -0
  197. pcapkit/const/tls/__init__.py +44 -0
  198. pcapkit/const/tls/content_type.py +99 -0
  199. pcapkit/const/tls/extension_type.py +382 -0
  200. pcapkit/const/tls/handshake_type.py +154 -0
  201. pcapkit/const/vlan/__init__.py +32 -0
  202. pcapkit/const/vlan/priority_level.py +85 -0
  203. pcapkit/corekit/__init__.py +64 -0
  204. pcapkit/corekit/checksum/__init__.py +24 -0
  205. pcapkit/corekit/checksum/internet.py +253 -0
  206. pcapkit/corekit/context.py +248 -0
  207. pcapkit/corekit/decorators.py +328 -0
  208. pcapkit/corekit/enum.py +742 -0
  209. pcapkit/corekit/fields/__init__.py +46 -0
  210. pcapkit/corekit/fields/collections.py +646 -0
  211. pcapkit/corekit/fields/field.py +643 -0
  212. pcapkit/corekit/fields/ipaddress.py +582 -0
  213. pcapkit/corekit/fields/misc.py +843 -0
  214. pcapkit/corekit/fields/numbers.py +1279 -0
  215. pcapkit/corekit/fields/strings.py +445 -0
  216. pcapkit/corekit/infoclass.py +1231 -0
  217. pcapkit/corekit/io.py +980 -0
  218. pcapkit/corekit/module.py +133 -0
  219. pcapkit/corekit/multidict.py +676 -0
  220. pcapkit/corekit/packet.py +179 -0
  221. pcapkit/corekit/protochain.py +266 -0
  222. pcapkit/corekit/schema/__init__.py +20 -0
  223. pcapkit/corekit/schema/byteorder.py +89 -0
  224. pcapkit/corekit/schema/ipaddress.py +210 -0
  225. pcapkit/corekit/schema/jumbogram.py +66 -0
  226. pcapkit/corekit/schema/padding.py +50 -0
  227. pcapkit/corekit/schema/shortread.py +150 -0
  228. pcapkit/corekit/sentinels.py +597 -0
  229. pcapkit/corekit/version.py +40 -0
  230. pcapkit/dumpkit/__init__.py +14 -0
  231. pcapkit/dumpkit/common.py +778 -0
  232. pcapkit/dumpkit/null.py +72 -0
  233. pcapkit/dumpkit/pcap.py +292 -0
  234. pcapkit/foundation/__init__.py +63 -0
  235. pcapkit/foundation/analysis/__init__.py +27 -0
  236. pcapkit/foundation/analysis/dtls.py +61 -0
  237. pcapkit/foundation/analysis/ip.py +88 -0
  238. pcapkit/foundation/analysis/tcp.py +87 -0
  239. pcapkit/foundation/engines/__init__.py +35 -0
  240. pcapkit/foundation/engines/_pcap_backend.py +358 -0
  241. pcapkit/foundation/engines/dpkt.py +680 -0
  242. pcapkit/foundation/engines/engine.py +318 -0
  243. pcapkit/foundation/engines/pcap.py +259 -0
  244. pcapkit/foundation/engines/pcap_ct.py +469 -0
  245. pcapkit/foundation/engines/pcapng.py +513 -0
  246. pcapkit/foundation/engines/pypcap.py +386 -0
  247. pcapkit/foundation/engines/pypcapfile.py +477 -0
  248. pcapkit/foundation/engines/pyshark.py +374 -0
  249. pcapkit/foundation/engines/scapy.py +451 -0
  250. pcapkit/foundation/extraction.py +1833 -0
  251. pcapkit/foundation/reassembly/__init__.py +55 -0
  252. pcapkit/foundation/reassembly/data/__init__.py +43 -0
  253. pcapkit/foundation/reassembly/data/data.py +300 -0
  254. pcapkit/foundation/reassembly/data/dtls.py +186 -0
  255. pcapkit/foundation/reassembly/data/ip.py +203 -0
  256. pcapkit/foundation/reassembly/data/tcp.py +296 -0
  257. pcapkit/foundation/reassembly/dtls.py +340 -0
  258. pcapkit/foundation/reassembly/ip.py +639 -0
  259. pcapkit/foundation/reassembly/ipv4.py +80 -0
  260. pcapkit/foundation/reassembly/ipv6.py +206 -0
  261. pcapkit/foundation/reassembly/reassembly.py +605 -0
  262. pcapkit/foundation/reassembly/tcp.py +870 -0
  263. pcapkit/foundation/registry/__init__.py +56 -0
  264. pcapkit/foundation/registry/foundation.py +362 -0
  265. pcapkit/foundation/registry/protocols/__init__.py +67 -0
  266. pcapkit/foundation/registry/protocols/application.py +119 -0
  267. pcapkit/foundation/registry/protocols/internet.py +506 -0
  268. pcapkit/foundation/registry/protocols/link.py +378 -0
  269. pcapkit/foundation/registry/protocols/misc.py +352 -0
  270. pcapkit/foundation/registry/protocols/protocol.py +519 -0
  271. pcapkit/foundation/registry/protocols/transport.py +647 -0
  272. pcapkit/foundation/traceflow/__init__.py +45 -0
  273. pcapkit/foundation/traceflow/data/__init__.py +17 -0
  274. pcapkit/foundation/traceflow/data/data.py +193 -0
  275. pcapkit/foundation/traceflow/data/tcp.py +212 -0
  276. pcapkit/foundation/traceflow/tcp.py +581 -0
  277. pcapkit/foundation/traceflow/traceflow.py +593 -0
  278. pcapkit/interface/__init__.py +23 -0
  279. pcapkit/interface/core.py +265 -0
  280. pcapkit/interface/misc.py +186 -0
  281. pcapkit/interface/registry.py +116 -0
  282. pcapkit/protocols/__init__.py +95 -0
  283. pcapkit/protocols/application/NotImplemented/bgp.py +0 -0
  284. pcapkit/protocols/application/NotImplemented/dhcp.py +0 -0
  285. pcapkit/protocols/application/NotImplemented/dhcpv6.py +0 -0
  286. pcapkit/protocols/application/NotImplemented/dns.py +0 -0
  287. pcapkit/protocols/application/NotImplemented/imap.py +0 -0
  288. pcapkit/protocols/application/NotImplemented/ldap.py +0 -0
  289. pcapkit/protocols/application/NotImplemented/mqtt.py +0 -0
  290. pcapkit/protocols/application/NotImplemented/nntp.py +0 -0
  291. pcapkit/protocols/application/NotImplemented/ntp.py +0 -0
  292. pcapkit/protocols/application/NotImplemented/onc_rpc.py +0 -0
  293. pcapkit/protocols/application/NotImplemented/pop.py +0 -0
  294. pcapkit/protocols/application/NotImplemented/rip.py +0 -0
  295. pcapkit/protocols/application/NotImplemented/rtp.py +0 -0
  296. pcapkit/protocols/application/NotImplemented/sip.py +0 -0
  297. pcapkit/protocols/application/NotImplemented/smtp.py +0 -0
  298. pcapkit/protocols/application/NotImplemented/snmp.py +0 -0
  299. pcapkit/protocols/application/NotImplemented/ssh.py +0 -0
  300. pcapkit/protocols/application/NotImplemented/telnet.py +0 -0
  301. pcapkit/protocols/application/NotImplemented/xmpp.py +0 -0
  302. pcapkit/protocols/application/__init__.py +79 -0
  303. pcapkit/protocols/application/application.py +189 -0
  304. pcapkit/protocols/application/drarp/__init__.py +14 -0
  305. pcapkit/protocols/application/drarp/protocol.py +53 -0
  306. pcapkit/protocols/application/dtls/__init__.py +30 -0
  307. pcapkit/protocols/application/dtls/data.py +150 -0
  308. pcapkit/protocols/application/dtls/protocol.py +1137 -0
  309. pcapkit/protocols/application/dtls/schema.py +157 -0
  310. pcapkit/protocols/application/ftp/__init__.py +27 -0
  311. pcapkit/protocols/application/ftp/data.py +72 -0
  312. pcapkit/protocols/application/ftp/protocol.py +410 -0
  313. pcapkit/protocols/application/ftp/schema.py +21 -0
  314. pcapkit/protocols/application/ftp_data/__init__.py +14 -0
  315. pcapkit/protocols/application/ftp_data/protocol.py +97 -0
  316. pcapkit/protocols/application/http/__init__.py +14 -0
  317. pcapkit/protocols/application/http/protocol.py +773 -0
  318. pcapkit/protocols/application/httpv1/__init__.py +28 -0
  319. pcapkit/protocols/application/httpv1/data.py +98 -0
  320. pcapkit/protocols/application/httpv1/protocol.py +610 -0
  321. pcapkit/protocols/application/httpv1/schema.py +29 -0
  322. pcapkit/protocols/application/httpv2/__init__.py +61 -0
  323. pcapkit/protocols/application/httpv2/data.py +347 -0
  324. pcapkit/protocols/application/httpv2/protocol.py +1724 -0
  325. pcapkit/protocols/application/httpv2/schema.py +430 -0
  326. pcapkit/protocols/application/ngap/__init__.py +29 -0
  327. pcapkit/protocols/application/ngap/data.py +124 -0
  328. pcapkit/protocols/application/ngap/protocol.py +578 -0
  329. pcapkit/protocols/application/ngap/schema.py +29 -0
  330. pcapkit/protocols/application/ospf/__init__.py +29 -0
  331. pcapkit/protocols/application/ospf/data.py +79 -0
  332. pcapkit/protocols/application/ospf/protocol.py +544 -0
  333. pcapkit/protocols/application/ospf/schema.py +109 -0
  334. pcapkit/protocols/application/rarp/__init__.py +14 -0
  335. pcapkit/protocols/application/rarp/protocol.py +111 -0
  336. pcapkit/protocols/application/ssl/__init__.py +43 -0
  337. pcapkit/protocols/application/ssl/data.py +322 -0
  338. pcapkit/protocols/application/ssl/protocol.py +1522 -0
  339. pcapkit/protocols/application/sslv2/__init__.py +32 -0
  340. pcapkit/protocols/application/sslv2/data.py +93 -0
  341. pcapkit/protocols/application/sslv2/protocol.py +543 -0
  342. pcapkit/protocols/application/sslv2/schema.py +304 -0
  343. pcapkit/protocols/application/sslv3/__init__.py +14 -0
  344. pcapkit/protocols/application/sslv3/protocol.py +51 -0
  345. pcapkit/protocols/application/tls/__init__.py +25 -0
  346. pcapkit/protocols/application/tls/data.py +40 -0
  347. pcapkit/protocols/application/tls/protocol.py +561 -0
  348. pcapkit/protocols/application/tls/schema.py +44 -0
  349. pcapkit/protocols/data.py +76 -0
  350. pcapkit/protocols/internet/NotImplemented/ecn.py +0 -0
  351. pcapkit/protocols/internet/NotImplemented/shim6.py +0 -0
  352. pcapkit/protocols/internet/__init__.py +87 -0
  353. pcapkit/protocols/internet/ah/__init__.py +25 -0
  354. pcapkit/protocols/internet/ah/data.py +39 -0
  355. pcapkit/protocols/internet/ah/protocol.py +343 -0
  356. pcapkit/protocols/internet/ah/schema.py +57 -0
  357. pcapkit/protocols/internet/esp/__init__.py +25 -0
  358. pcapkit/protocols/internet/esp/data.py +71 -0
  359. pcapkit/protocols/internet/esp/protocol.py +1509 -0
  360. pcapkit/protocols/internet/esp/schema.py +46 -0
  361. pcapkit/protocols/internet/hip/__init__.py +169 -0
  362. pcapkit/protocols/internet/hip/data.py +1109 -0
  363. pcapkit/protocols/internet/hip/protocol.py +5697 -0
  364. pcapkit/protocols/internet/hip/schema.py +1654 -0
  365. pcapkit/protocols/internet/hopopt/__init__.py +80 -0
  366. pcapkit/protocols/internet/hopopt/data.py +445 -0
  367. pcapkit/protocols/internet/hopopt/protocol.py +2346 -0
  368. pcapkit/protocols/internet/hopopt/schema.py +686 -0
  369. pcapkit/protocols/internet/icmp/__init__.py +14 -0
  370. pcapkit/protocols/internet/icmp/protocol.py +201 -0
  371. pcapkit/protocols/internet/icmpv4/__init__.py +38 -0
  372. pcapkit/protocols/internet/icmpv4/data.py +153 -0
  373. pcapkit/protocols/internet/icmpv4/protocol.py +652 -0
  374. pcapkit/protocols/internet/icmpv4/schema.py +135 -0
  375. pcapkit/protocols/internet/icmpv6/__init__.py +40 -0
  376. pcapkit/protocols/internet/icmpv6/data.py +174 -0
  377. pcapkit/protocols/internet/icmpv6/protocol.py +735 -0
  378. pcapkit/protocols/internet/icmpv6/schema.py +144 -0
  379. pcapkit/protocols/internet/igmp/__init__.py +25 -0
  380. pcapkit/protocols/internet/igmp/data.py +59 -0
  381. pcapkit/protocols/internet/igmp/protocol.py +491 -0
  382. pcapkit/protocols/internet/igmp/schema.py +54 -0
  383. pcapkit/protocols/internet/igmpv1/__init__.py +14 -0
  384. pcapkit/protocols/internet/igmpv1/protocol.py +63 -0
  385. pcapkit/protocols/internet/igmpv2/__init__.py +14 -0
  386. pcapkit/protocols/internet/igmpv2/protocol.py +65 -0
  387. pcapkit/protocols/internet/igmpv3/__init__.py +32 -0
  388. pcapkit/protocols/internet/igmpv3/data.py +150 -0
  389. pcapkit/protocols/internet/igmpv3/protocol.py +587 -0
  390. pcapkit/protocols/internet/igmpv3/schema.py +373 -0
  391. pcapkit/protocols/internet/internet.py +566 -0
  392. pcapkit/protocols/internet/ip/__init__.py +14 -0
  393. pcapkit/protocols/internet/ip/protocol.py +205 -0
  394. pcapkit/protocols/internet/ipsec/__init__.py +14 -0
  395. pcapkit/protocols/internet/ipsec/protocol.py +48 -0
  396. pcapkit/protocols/internet/ipv4/__init__.py +68 -0
  397. pcapkit/protocols/internet/ipv4/data.py +470 -0
  398. pcapkit/protocols/internet/ipv4/protocol.py +2293 -0
  399. pcapkit/protocols/internet/ipv4/schema.py +747 -0
  400. pcapkit/protocols/internet/ipv6/__init__.py +25 -0
  401. pcapkit/protocols/internet/ipv6/data.py +83 -0
  402. pcapkit/protocols/internet/ipv6/protocol.py +731 -0
  403. pcapkit/protocols/internet/ipv6/schema.py +176 -0
  404. pcapkit/protocols/internet/ipv6_ext/__init__.py +25 -0
  405. pcapkit/protocols/internet/ipv6_ext/data.py +52 -0
  406. pcapkit/protocols/internet/ipv6_ext/protocol.py +718 -0
  407. pcapkit/protocols/internet/ipv6_ext/schema.py +397 -0
  408. pcapkit/protocols/internet/ipv6_frag/__init__.py +25 -0
  409. pcapkit/protocols/internet/ipv6_frag/data.py +41 -0
  410. pcapkit/protocols/internet/ipv6_frag/protocol.py +320 -0
  411. pcapkit/protocols/internet/ipv6_frag/schema.py +51 -0
  412. pcapkit/protocols/internet/ipv6_opts/__init__.py +83 -0
  413. pcapkit/protocols/internet/ipv6_opts/data.py +462 -0
  414. pcapkit/protocols/internet/ipv6_opts/protocol.py +2335 -0
  415. pcapkit/protocols/internet/ipv6_opts/schema.py +695 -0
  416. pcapkit/protocols/internet/ipv6_route/__init__.py +34 -0
  417. pcapkit/protocols/internet/ipv6_route/data.py +113 -0
  418. pcapkit/protocols/internet/ipv6_route/protocol.py +936 -0
  419. pcapkit/protocols/internet/ipv6_route/schema.py +299 -0
  420. pcapkit/protocols/internet/ipx/__init__.py +26 -0
  421. pcapkit/protocols/internet/ipx/data.py +59 -0
  422. pcapkit/protocols/internet/ipx/protocol.py +387 -0
  423. pcapkit/protocols/internet/ipx/schema.py +53 -0
  424. pcapkit/protocols/internet/mh/__init__.py +433 -0
  425. pcapkit/protocols/internet/mh/data.py +2464 -0
  426. pcapkit/protocols/internet/mh/protocol.py +11753 -0
  427. pcapkit/protocols/internet/mh/schema.py +3367 -0
  428. pcapkit/protocols/link/NotImplemented/dsl.py +0 -0
  429. pcapkit/protocols/link/NotImplemented/eapol.py +1 -0
  430. pcapkit/protocols/link/NotImplemented/fddi.py +0 -0
  431. pcapkit/protocols/link/NotImplemented/isdn.py +0 -0
  432. pcapkit/protocols/link/NotImplemented/ndp.py +0 -0
  433. pcapkit/protocols/link/NotImplemented/ppp.py +0 -0
  434. pcapkit/protocols/link/__init__.py +80 -0
  435. pcapkit/protocols/link/arp/__init__.py +27 -0
  436. pcapkit/protocols/link/arp/data.py +73 -0
  437. pcapkit/protocols/link/arp/protocol.py +513 -0
  438. pcapkit/protocols/link/arp/schema.py +49 -0
  439. pcapkit/protocols/link/c_tag/__init__.py +14 -0
  440. pcapkit/protocols/link/c_tag/protocol.py +99 -0
  441. pcapkit/protocols/link/ethernet/__init__.py +25 -0
  442. pcapkit/protocols/link/ethernet/data.py +27 -0
  443. pcapkit/protocols/link/ethernet/protocol.py +221 -0
  444. pcapkit/protocols/link/ethernet/schema.py +72 -0
  445. pcapkit/protocols/link/frad/__init__.py +25 -0
  446. pcapkit/protocols/link/frad/data.py +47 -0
  447. pcapkit/protocols/link/frad/protocol.py +470 -0
  448. pcapkit/protocols/link/frad/schema.py +112 -0
  449. pcapkit/protocols/link/gre/__init__.py +25 -0
  450. pcapkit/protocols/link/gre/data.py +64 -0
  451. pcapkit/protocols/link/gre/protocol.py +396 -0
  452. pcapkit/protocols/link/gre/schema.py +91 -0
  453. pcapkit/protocols/link/ieee802_11/__init__.py +30 -0
  454. pcapkit/protocols/link/ieee802_11/data.py +171 -0
  455. pcapkit/protocols/link/ieee802_11/protocol.py +612 -0
  456. pcapkit/protocols/link/ieee802_11/schema.py +163 -0
  457. pcapkit/protocols/link/inarp/__init__.py +14 -0
  458. pcapkit/protocols/link/inarp/protocol.py +55 -0
  459. pcapkit/protocols/link/l2tp/__init__.py +26 -0
  460. pcapkit/protocols/link/l2tp/data.py +72 -0
  461. pcapkit/protocols/link/l2tp/protocol.py +285 -0
  462. pcapkit/protocols/link/l2tp/schema.py +122 -0
  463. pcapkit/protocols/link/l2tpv2/__init__.py +14 -0
  464. pcapkit/protocols/link/l2tpv2/protocol.py +440 -0
  465. pcapkit/protocols/link/link.py +226 -0
  466. pcapkit/protocols/link/linux_sll/__init__.py +14 -0
  467. pcapkit/protocols/link/linux_sll/protocol.py +421 -0
  468. pcapkit/protocols/link/linux_sll1/__init__.py +25 -0
  469. pcapkit/protocols/link/linux_sll1/data.py +41 -0
  470. pcapkit/protocols/link/linux_sll1/protocol.py +247 -0
  471. pcapkit/protocols/link/linux_sll1/schema.py +46 -0
  472. pcapkit/protocols/link/linux_sll2/__init__.py +25 -0
  473. pcapkit/protocols/link/linux_sll2/data.py +47 -0
  474. pcapkit/protocols/link/linux_sll2/protocol.py +257 -0
  475. pcapkit/protocols/link/linux_sll2/schema.py +52 -0
  476. pcapkit/protocols/link/loopback/__init__.py +25 -0
  477. pcapkit/protocols/link/loopback/data.py +25 -0
  478. pcapkit/protocols/link/loopback/protocol.py +334 -0
  479. pcapkit/protocols/link/loopback/schema.py +33 -0
  480. pcapkit/protocols/link/netlink/__init__.py +25 -0
  481. pcapkit/protocols/link/netlink/data.py +40 -0
  482. pcapkit/protocols/link/netlink/protocol.py +390 -0
  483. pcapkit/protocols/link/netlink/schema.py +44 -0
  484. pcapkit/protocols/link/radiotap/__init__.py +103 -0
  485. pcapkit/protocols/link/radiotap/data.py +768 -0
  486. pcapkit/protocols/link/radiotap/protocol.py +2264 -0
  487. pcapkit/protocols/link/radiotap/schema.py +662 -0
  488. pcapkit/protocols/link/s_tag/__init__.py +14 -0
  489. pcapkit/protocols/link/s_tag/protocol.py +102 -0
  490. pcapkit/protocols/link/vlan/__init__.py +27 -0
  491. pcapkit/protocols/link/vlan/data.py +47 -0
  492. pcapkit/protocols/link/vlan/protocol.py +269 -0
  493. pcapkit/protocols/link/vlan/schema.py +77 -0
  494. pcapkit/protocols/misc/__init__.py +60 -0
  495. pcapkit/protocols/misc/checksum/__init__.py +28 -0
  496. pcapkit/protocols/misc/checksum/ip_pseudo/__init__.py +25 -0
  497. pcapkit/protocols/misc/checksum/ip_pseudo/data.py +41 -0
  498. pcapkit/protocols/misc/checksum/ip_pseudo/protocol.py +692 -0
  499. pcapkit/protocols/misc/checksum/ip_pseudo/schema.py +118 -0
  500. pcapkit/protocols/misc/no_payload/__init__.py +25 -0
  501. pcapkit/protocols/misc/no_payload/data.py +17 -0
  502. pcapkit/protocols/misc/no_payload/protocol.py +164 -0
  503. pcapkit/protocols/misc/no_payload/schema.py +17 -0
  504. pcapkit/protocols/misc/pcap/__init__.py +30 -0
  505. pcapkit/protocols/misc/pcap/frame/__init__.py +26 -0
  506. pcapkit/protocols/misc/pcap/frame/data.py +62 -0
  507. pcapkit/protocols/misc/pcap/frame/protocol.py +673 -0
  508. pcapkit/protocols/misc/pcap/frame/schema.py +47 -0
  509. pcapkit/protocols/misc/pcap/header/__init__.py +26 -0
  510. pcapkit/protocols/misc/pcap/header/data.py +52 -0
  511. pcapkit/protocols/misc/pcap/header/protocol.py +391 -0
  512. pcapkit/protocols/misc/pcap/header/schema.py +103 -0
  513. pcapkit/protocols/misc/pcapng/__init__.py +160 -0
  514. pcapkit/protocols/misc/pcapng/data.py +1102 -0
  515. pcapkit/protocols/misc/pcapng/protocol.py +6960 -0
  516. pcapkit/protocols/misc/pcapng/schema.py +2825 -0
  517. pcapkit/protocols/misc/raw/__init__.py +25 -0
  518. pcapkit/protocols/misc/raw/data.py +35 -0
  519. pcapkit/protocols/misc/raw/protocol.py +188 -0
  520. pcapkit/protocols/misc/raw/schema.py +24 -0
  521. pcapkit/protocols/protocol.py +3145 -0
  522. pcapkit/protocols/schema.py +1295 -0
  523. pcapkit/protocols/transport/NotImplemented/rsvp.py +0 -0
  524. pcapkit/protocols/transport/__init__.py +47 -0
  525. pcapkit/protocols/transport/dccp/__init__.py +57 -0
  526. pcapkit/protocols/transport/dccp/data.py +275 -0
  527. pcapkit/protocols/transport/dccp/protocol.py +1525 -0
  528. pcapkit/protocols/transport/dccp/schema.py +381 -0
  529. pcapkit/protocols/transport/sctp/__init__.py +147 -0
  530. pcapkit/protocols/transport/sctp/data.py +633 -0
  531. pcapkit/protocols/transport/sctp/protocol.py +3937 -0
  532. pcapkit/protocols/transport/sctp/schema.py +1007 -0
  533. pcapkit/protocols/transport/tcp/__init__.py +108 -0
  534. pcapkit/protocols/transport/tcp/data.py +637 -0
  535. pcapkit/protocols/transport/tcp/protocol.py +3640 -0
  536. pcapkit/protocols/transport/tcp/schema.py +1131 -0
  537. pcapkit/protocols/transport/transport.py +371 -0
  538. pcapkit/protocols/transport/udp/__init__.py +25 -0
  539. pcapkit/protocols/transport/udp/data.py +38 -0
  540. pcapkit/protocols/transport/udp/protocol.py +384 -0
  541. pcapkit/protocols/transport/udp/schema.py +44 -0
  542. pcapkit/py.typed +0 -0
  543. pcapkit/toolkit/__init__.py +88 -0
  544. pcapkit/toolkit/dpkt.py +909 -0
  545. pcapkit/toolkit/pcap.py +510 -0
  546. pcapkit/toolkit/pcap_ct.py +160 -0
  547. pcapkit/toolkit/pcapng.py +287 -0
  548. pcapkit/toolkit/pypcap.py +158 -0
  549. pcapkit/toolkit/pypcapfile.py +917 -0
  550. pcapkit/toolkit/pyshark.py +628 -0
  551. pcapkit/toolkit/scapy.py +761 -0
  552. pcapkit/utilities/__init__.py +41 -0
  553. pcapkit/utilities/chardet.py +64 -0
  554. pcapkit/utilities/compat.py +173 -0
  555. pcapkit/utilities/config.py +446 -0
  556. pcapkit/utilities/contextvars.py +57 -0
  557. pcapkit/utilities/datetime.py +117 -0
  558. pcapkit/utilities/exceptions.py +845 -0
  559. pcapkit/utilities/importlib.py +123 -0
  560. pcapkit/utilities/inspect.py +55 -0
  561. pcapkit/utilities/logging.py +395 -0
  562. pcapkit/utilities/pickle.py +181 -0
  563. pcapkit/utilities/warnings.py +538 -0
  564. pcapkit/vendor/__init__.py +220 -0
  565. pcapkit/vendor/__main__.py +253 -0
  566. pcapkit/vendor/arp/__init__.py +27 -0
  567. pcapkit/vendor/arp/hardware.py +29 -0
  568. pcapkit/vendor/arp/operation.py +29 -0
  569. pcapkit/vendor/dccp/__init__.py +44 -0
  570. pcapkit/vendor/dccp/ack_vector_state.py +29 -0
  571. pcapkit/vendor/dccp/drop_code.py +29 -0
  572. pcapkit/vendor/dccp/feature.py +29 -0
  573. pcapkit/vendor/dccp/option.py +29 -0
  574. pcapkit/vendor/dccp/packet_type.py +29 -0
  575. pcapkit/vendor/dccp/reset_code.py +29 -0
  576. pcapkit/vendor/default.py +823 -0
  577. pcapkit/vendor/esp/__init__.py +32 -0
  578. pcapkit/vendor/esp/cipher.py +114 -0
  579. pcapkit/vendor/esp/integrity.py +111 -0
  580. pcapkit/vendor/ftp/__init__.py +27 -0
  581. pcapkit/vendor/ftp/command.py +577 -0
  582. pcapkit/vendor/ftp/return_code.py +363 -0
  583. pcapkit/vendor/hip/__init__.py +94 -0
  584. pcapkit/vendor/hip/certificate.py +29 -0
  585. pcapkit/vendor/hip/cipher.py +29 -0
  586. pcapkit/vendor/hip/di.py +29 -0
  587. pcapkit/vendor/hip/ecdsa_curve.py +29 -0
  588. pcapkit/vendor/hip/ecdsa_low_curve.py +29 -0
  589. pcapkit/vendor/hip/eddsa_curve.py +85 -0
  590. pcapkit/vendor/hip/esp_transform_suite.py +29 -0
  591. pcapkit/vendor/hip/group.py +87 -0
  592. pcapkit/vendor/hip/hi_algorithm.py +29 -0
  593. pcapkit/vendor/hip/hit_suite.py +29 -0
  594. pcapkit/vendor/hip/nat_traversal.py +29 -0
  595. pcapkit/vendor/hip/notify_message.py +29 -0
  596. pcapkit/vendor/hip/packet.py +88 -0
  597. pcapkit/vendor/hip/parameter.py +88 -0
  598. pcapkit/vendor/hip/registration.py +29 -0
  599. pcapkit/vendor/hip/registration_failure.py +29 -0
  600. pcapkit/vendor/hip/suite.py +29 -0
  601. pcapkit/vendor/hip/transport.py +29 -0
  602. pcapkit/vendor/http/__init__.py +39 -0
  603. pcapkit/vendor/http/error_code.py +94 -0
  604. pcapkit/vendor/http/frame.py +91 -0
  605. pcapkit/vendor/http/method.py +309 -0
  606. pcapkit/vendor/http/setting.py +93 -0
  607. pcapkit/vendor/http/status_code.py +233 -0
  608. pcapkit/vendor/icmp/__init__.py +40 -0
  609. pcapkit/vendor/icmp/destination_unreachable_code.py +80 -0
  610. pcapkit/vendor/icmp/parameter_problem_code.py +80 -0
  611. pcapkit/vendor/icmp/time_exceeded_code.py +80 -0
  612. pcapkit/vendor/icmp/type.py +78 -0
  613. pcapkit/vendor/icmpv6/__init__.py +40 -0
  614. pcapkit/vendor/icmpv6/destination_unreachable_code.py +80 -0
  615. pcapkit/vendor/icmpv6/parameter_problem_code.py +80 -0
  616. pcapkit/vendor/icmpv6/time_exceeded_code.py +73 -0
  617. pcapkit/vendor/icmpv6/type.py +78 -0
  618. pcapkit/vendor/ieee802_11/__init__.py +54 -0
  619. pcapkit/vendor/ieee802_11/control_subtype.py +107 -0
  620. pcapkit/vendor/ieee802_11/data_subtype.py +106 -0
  621. pcapkit/vendor/ieee802_11/extension_subtype.py +95 -0
  622. pcapkit/vendor/ieee802_11/management_subtype.py +102 -0
  623. pcapkit/vendor/ieee802_11/type.py +90 -0
  624. pcapkit/vendor/igmp/__init__.py +27 -0
  625. pcapkit/vendor/igmp/record_type.py +88 -0
  626. pcapkit/vendor/igmp/type.py +77 -0
  627. pcapkit/vendor/ipv4/__init__.py +59 -0
  628. pcapkit/vendor/ipv4/classification_level.py +90 -0
  629. pcapkit/vendor/ipv4/option_class.py +80 -0
  630. pcapkit/vendor/ipv4/option_number.py +105 -0
  631. pcapkit/vendor/ipv4/protection_authority.py +84 -0
  632. pcapkit/vendor/ipv4/qs_function.py +78 -0
  633. pcapkit/vendor/ipv4/router_alert.py +94 -0
  634. pcapkit/vendor/ipv4/tos_del.py +78 -0
  635. pcapkit/vendor/ipv4/tos_ecn.py +95 -0
  636. pcapkit/vendor/ipv4/tos_pre.py +84 -0
  637. pcapkit/vendor/ipv4/tos_rel.py +78 -0
  638. pcapkit/vendor/ipv4/tos_thr.py +78 -0
  639. pcapkit/vendor/ipv4/ts_flag.py +79 -0
  640. pcapkit/vendor/ipv6/__init__.py +53 -0
  641. pcapkit/vendor/ipv6/extension_header.py +220 -0
  642. pcapkit/vendor/ipv6/option.py +104 -0
  643. pcapkit/vendor/ipv6/option_action.py +90 -0
  644. pcapkit/vendor/ipv6/qs_function.py +78 -0
  645. pcapkit/vendor/ipv6/router_alert.py +93 -0
  646. pcapkit/vendor/ipv6/routing.py +87 -0
  647. pcapkit/vendor/ipv6/seed_id.py +81 -0
  648. pcapkit/vendor/ipv6/smf_dpd_mode.py +78 -0
  649. pcapkit/vendor/ipv6/tagger_id.py +81 -0
  650. pcapkit/vendor/ipx/__init__.py +39 -0
  651. pcapkit/vendor/ipx/packet.py +149 -0
  652. pcapkit/vendor/ipx/socket.py +240 -0
  653. pcapkit/vendor/l2tp/__init__.py +21 -0
  654. pcapkit/vendor/l2tp/type.py +79 -0
  655. pcapkit/vendor/linux/__init__.py +21 -0
  656. pcapkit/vendor/linux/arphrd.py +100 -0
  657. pcapkit/vendor/mh/__init__.py +206 -0
  658. pcapkit/vendor/mh/access_type.py +87 -0
  659. pcapkit/vendor/mh/ack_status_code.py +88 -0
  660. pcapkit/vendor/mh/ani_suboption.py +88 -0
  661. pcapkit/vendor/mh/auth_subtype.py +83 -0
  662. pcapkit/vendor/mh/binding_ack_flag.py +164 -0
  663. pcapkit/vendor/mh/binding_error.py +78 -0
  664. pcapkit/vendor/mh/binding_revocation.py +87 -0
  665. pcapkit/vendor/mh/binding_update_flag.py +163 -0
  666. pcapkit/vendor/mh/cga_extension.py +91 -0
  667. pcapkit/vendor/mh/cga_sec.py +91 -0
  668. pcapkit/vendor/mh/cga_type.py +74 -0
  669. pcapkit/vendor/mh/dhcp_support_mode.py +77 -0
  670. pcapkit/vendor/mh/dns_status_code.py +87 -0
  671. pcapkit/vendor/mh/dsmip6_tls_packet.py +87 -0
  672. pcapkit/vendor/mh/dsmipv6_home_address.py +87 -0
  673. pcapkit/vendor/mh/enumerating_algorithm.py +82 -0
  674. pcapkit/vendor/mh/fb_ack_status.py +87 -0
  675. pcapkit/vendor/mh/fb_action.py +88 -0
  676. pcapkit/vendor/mh/fb_indication_trigger.py +87 -0
  677. pcapkit/vendor/mh/fb_type.py +88 -0
  678. pcapkit/vendor/mh/flow_id_status.py +87 -0
  679. pcapkit/vendor/mh/flow_id_suboption.py +87 -0
  680. pcapkit/vendor/mh/handoff_type.py +87 -0
  681. pcapkit/vendor/mh/handover_ack_flag.py +159 -0
  682. pcapkit/vendor/mh/handover_ack_status.py +87 -0
  683. pcapkit/vendor/mh/handover_initiate_flag.py +159 -0
  684. pcapkit/vendor/mh/handover_initiate_status.py +87 -0
  685. pcapkit/vendor/mh/home_address_reply.py +87 -0
  686. pcapkit/vendor/mh/lla_code.py +97 -0
  687. pcapkit/vendor/mh/lma_mag_suboption.py +88 -0
  688. pcapkit/vendor/mh/mn_group_id.py +87 -0
  689. pcapkit/vendor/mh/mn_id_subtype.py +87 -0
  690. pcapkit/vendor/mh/operator_id.py +87 -0
  691. pcapkit/vendor/mh/option.py +83 -0
  692. pcapkit/vendor/mh/packet.py +82 -0
  693. pcapkit/vendor/mh/qos_attribute.py +87 -0
  694. pcapkit/vendor/mh/revocation_status_code.py +87 -0
  695. pcapkit/vendor/mh/revocation_trigger.py +87 -0
  696. pcapkit/vendor/mh/status_code.py +91 -0
  697. pcapkit/vendor/mh/traffic_selector.py +87 -0
  698. pcapkit/vendor/mh/upa_status.py +87 -0
  699. pcapkit/vendor/mh/upn_reason.py +87 -0
  700. pcapkit/vendor/ngap/__init__.py +31 -0
  701. pcapkit/vendor/ngap/procedure_code.py +233 -0
  702. pcapkit/vendor/ngap/protocol_ie.py +201 -0
  703. pcapkit/vendor/ospf/__init__.py +27 -0
  704. pcapkit/vendor/ospf/authentication.py +29 -0
  705. pcapkit/vendor/ospf/packet.py +29 -0
  706. pcapkit/vendor/pcapng/__init__.py +55 -0
  707. pcapkit/vendor/pcapng/block_type.py +102 -0
  708. pcapkit/vendor/pcapng/filter_type.py +77 -0
  709. pcapkit/vendor/pcapng/hash_algorithm.py +82 -0
  710. pcapkit/vendor/pcapng/option_type.py +477 -0
  711. pcapkit/vendor/pcapng/record_type.py +81 -0
  712. pcapkit/vendor/pcapng/secrets_type.py +80 -0
  713. pcapkit/vendor/pcapng/tls_key_label.py +180 -0
  714. pcapkit/vendor/pcapng/verdict_type.py +79 -0
  715. pcapkit/vendor/radiotap/__init__.py +86 -0
  716. pcapkit/vendor/radiotap/ampdu_flags.py +46 -0
  717. pcapkit/vendor/radiotap/channel_flags.py +51 -0
  718. pcapkit/vendor/radiotap/eht_known.py +59 -0
  719. pcapkit/vendor/radiotap/field_type.py +151 -0
  720. pcapkit/vendor/radiotap/flags.py +307 -0
  721. pcapkit/vendor/radiotap/he_data1_known.py +54 -0
  722. pcapkit/vendor/radiotap/he_data2_known.py +49 -0
  723. pcapkit/vendor/radiotap/he_mu_flags1_known.py +48 -0
  724. pcapkit/vendor/radiotap/he_mu_flags2_known.py +42 -0
  725. pcapkit/vendor/radiotap/he_mu_other_user_known.py +38 -0
  726. pcapkit/vendor/radiotap/lsig_data1.py +40 -0
  727. pcapkit/vendor/radiotap/mcs_known.py +48 -0
  728. pcapkit/vendor/radiotap/rx_flags.py +39 -0
  729. pcapkit/vendor/radiotap/s1g_known.py +46 -0
  730. pcapkit/vendor/radiotap/timestamp_flags.py +40 -0
  731. pcapkit/vendor/radiotap/tx_flags.py +44 -0
  732. pcapkit/vendor/radiotap/usig_common_known.py +48 -0
  733. pcapkit/vendor/radiotap/vht_coding.py +42 -0
  734. pcapkit/vendor/radiotap/vht_flags.py +44 -0
  735. pcapkit/vendor/radiotap/vht_known.py +47 -0
  736. pcapkit/vendor/reg/__init__.py +47 -0
  737. pcapkit/vendor/reg/apptype/__init__.py +36 -0
  738. pcapkit/vendor/reg/apptype/apptype.py +1320 -0
  739. pcapkit/vendor/reg/apptype/dccp.py +27 -0
  740. pcapkit/vendor/reg/apptype/sctp.py +27 -0
  741. pcapkit/vendor/reg/apptype/tcp.py +27 -0
  742. pcapkit/vendor/reg/apptype/udp.py +27 -0
  743. pcapkit/vendor/reg/ethertype.py +175 -0
  744. pcapkit/vendor/reg/linktype.py +210 -0
  745. pcapkit/vendor/reg/transtype.py +116 -0
  746. pcapkit/vendor/sctp/__init__.py +37 -0
  747. pcapkit/vendor/sctp/cause_code.py +29 -0
  748. pcapkit/vendor/sctp/chunk.py +29 -0
  749. pcapkit/vendor/sctp/parameter.py +29 -0
  750. pcapkit/vendor/sctp/payload_protocol_identifier.py +34 -0
  751. pcapkit/vendor/sslv2/__init__.py +24 -0
  752. pcapkit/vendor/sslv2/handshake_type.py +100 -0
  753. pcapkit/vendor/sslv2/version.py +95 -0
  754. pcapkit/vendor/tcp/__init__.py +35 -0
  755. pcapkit/vendor/tcp/checksum.py +80 -0
  756. pcapkit/vendor/tcp/flags.py +180 -0
  757. pcapkit/vendor/tcp/mp_tcp_option.py +90 -0
  758. pcapkit/vendor/tcp/option.py +103 -0
  759. pcapkit/vendor/tls/__init__.py +30 -0
  760. pcapkit/vendor/tls/content_type.py +142 -0
  761. pcapkit/vendor/tls/extension_type.py +151 -0
  762. pcapkit/vendor/tls/handshake_type.py +154 -0
  763. pcapkit/vendor/vlan/__init__.py +23 -0
  764. pcapkit/vendor/vlan/priority_level.py +97 -0
  765. pypcapkit-1.6.2.dist-info/METADATA +199 -0
  766. pypcapkit-1.6.2.dist-info/RECORD +770 -0
  767. pypcapkit-1.6.2.dist-info/WHEEL +5 -0
  768. pypcapkit-1.6.2.dist-info/entry_points.txt +3 -0
  769. pypcapkit-1.6.2.dist-info/licenses/LICENSE +29 -0
  770. pypcapkit-1.6.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1724 @@
1
+ # -*- coding: utf-8 -*-
2
+ """HTTP/2 - Hypertext Transfer Protocol
3
+ ==========================================
4
+
5
+ .. module:: pcapkit.protocols.application.httpv2.protocol
6
+
7
+ :mod:`pcapkit.protocols.application.httpv2.protocol` holds
8
+ :class:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2`, the extractor for
9
+ the Hypertext Transfer Protocol (HTTP/2) [*]_, whose frame is:
10
+
11
+ ======= ========= ===================== ==========================
12
+ Octets Bits Name Description
13
+ ======= ========= ===================== ==========================
14
+ 0 0 ``http.length`` Payload Length
15
+ 3 24 ``http.type`` Type
16
+ 4 32 ``http.flags`` Flags
17
+ 5 40 Reserved
18
+ 5 41 ``http.sid`` Stream Identifier
19
+ 9 72 ``http.payload`` Frame Payload
20
+ ======= ========= ===================== ==========================
21
+
22
+ .. [*] https://en.wikipedia.org/wiki/HTTP/2
23
+
24
+ Frames in One Segment
25
+ ---------------------
26
+
27
+ A whole frame after the first in a TCP segment is dissected as a further
28
+ :class:`HTTPv2` layer, the previous frame's payload (:issue:`2536`), as
29
+ :class:`~pcapkit.protocols.application.tls.protocol.TLS` chains records: a ``SETTINGS``
30
+ frame followed by a ``WINDOW_UPDATE`` reads ``TCP:HTTP/2:HTTP/2``. The
31
+ exceptions:
32
+
33
+ * A whole frame that fails to decode becomes
34
+ :class:`~pcapkit.protocols.misc.raw.protocol.Raw` together with everything after it,
35
+ with the parser's ``error``.
36
+ * A frame the segment ends inside, its header or its payload cut short, stays
37
+ raw, with no error.
38
+ * A parse told to stop at HTTP/2 (``protocol='HTTP/2'`` or
39
+ ``layer='Application'``) keeps the rest of the segment raw.
40
+ * Each frame is a layer, so :data:`~pcapkit.utilities.config.FRAME_LAYER_LIMIT`
41
+ bounds how many are dissected.
42
+
43
+ .. versionchanged:: 1.5.0
44
+
45
+ A frame's Length counts its payload alone, not the 9-octet frame header,
46
+ as :rfc:`9113#section-4.1` defines it, and the payload is read to that
47
+ Length rather than to the end of the buffer (:issue:`1121`,
48
+ :issue:`1243`). A frame rebuilds byte for byte: ``END_STREAM``, undefined
49
+ flag bits, the reserved bits, a zero Pad Length, duplicate SETTINGS
50
+ entries and the payload of an unpadded DATA, HEADERS or PUSH_PROMISE frame
51
+ are kept (:issue:`652`, :issue:`668`, :issue:`1244`, :issue:`1245`,
52
+ :issue:`1246`, :issue:`1247`).
53
+
54
+ .. versionremoved:: 1.6.0
55
+
56
+ ``pcapkit.protocols.application.httpv2.HTTP``, with no alias. The
57
+ class is renamed :class:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2`,
58
+ after its module (:issue:`2529`).
59
+
60
+ """
61
+ import collections
62
+ from typing import TYPE_CHECKING, cast
63
+
64
+ from pcapkit.const.http.error_code import ErrorCode as Enum_ErrorCode
65
+ from pcapkit.const.http.frame import Frame as Enum_Frame
66
+ from pcapkit.const.http.setting import Setting as Enum_Setting
67
+ from pcapkit.corekit.decorators import beholder
68
+ from pcapkit.corekit.multidict import MultiDict, OrderedMultiDict
69
+ from pcapkit.protocols.application.http.protocol import _HTTP2_PREFACE
70
+ from pcapkit.protocols.application.http.protocol import HTTP as HTTPBase
71
+ from pcapkit.protocols.application.httpv2.data import ContinuationFrame as Data_ContinuationFrame
72
+ from pcapkit.protocols.application.httpv2.data import \
73
+ ContinuationFrameFlags as Data_ContinuationFrameFlags
74
+ from pcapkit.protocols.application.httpv2.data import DataFrame as Data_DataFrame
75
+ from pcapkit.protocols.application.httpv2.data import DataFrameFlags as Data_DataFrameFlags
76
+ from pcapkit.protocols.application.httpv2.data import Flags as Data_Flags
77
+ from pcapkit.protocols.application.httpv2.data import GoawayFrame as Data_GoawayFrame
78
+ from pcapkit.protocols.application.httpv2.data import HeadersFrame as Data_HeadersFrame
79
+ from pcapkit.protocols.application.httpv2.data import HeadersFrameFlags as Data_HeadersFrameFlags
80
+ from pcapkit.protocols.application.httpv2.data import HTTPv2 as Data_HTTP
81
+ from pcapkit.protocols.application.httpv2.data import PingFrame as Data_PingFrame
82
+ from pcapkit.protocols.application.httpv2.data import PingFrameFlags as Data_PingFrameFlags
83
+ from pcapkit.protocols.application.httpv2.data import PriorityFrame as Data_PriorityFrame
84
+ from pcapkit.protocols.application.httpv2.data import PushPromiseFrame as Data_PushPromiseFrame
85
+ from pcapkit.protocols.application.httpv2.data import \
86
+ PushPromiseFrameFlags as Data_PushPromiseFrameFlags
87
+ from pcapkit.protocols.application.httpv2.data import RSTStreamFrame as Data_RSTStreamFrame
88
+ from pcapkit.protocols.application.httpv2.data import Settings as Data_Settings
89
+ from pcapkit.protocols.application.httpv2.data import SettingsFrame as Data_SettingsFrame
90
+ from pcapkit.protocols.application.httpv2.data import SettingsFrameFlags as Data_SettingsFrameFlags
91
+ from pcapkit.protocols.application.httpv2.data import UnassignedFrame as Data_UnassignedFrame
92
+ from pcapkit.protocols.application.httpv2.data import WindowUpdateFrame as Data_WindowUpdateFrame
93
+ from pcapkit.protocols.application.httpv2.schema import \
94
+ ContinuationFrame as Schema_ContinuationFrame
95
+ from pcapkit.protocols.application.httpv2.schema import DataFrame as Schema_DataFrame
96
+ from pcapkit.protocols.application.httpv2.schema import FrameType as Schema_FrameType
97
+ from pcapkit.protocols.application.httpv2.schema import GoawayFrame as Schema_GoawayFrame
98
+ from pcapkit.protocols.application.httpv2.schema import HeadersFrame as Schema_HeadersFrame
99
+ from pcapkit.protocols.application.httpv2.schema import HTTPv2 as Schema_HTTP
100
+ from pcapkit.protocols.application.httpv2.schema import PingFrame as Schema_PingFrame
101
+ from pcapkit.protocols.application.httpv2.schema import PriorityFrame as Schema_PriorityFrame
102
+ from pcapkit.protocols.application.httpv2.schema import PushPromiseFrame as Schema_PushPromiseFrame
103
+ from pcapkit.protocols.application.httpv2.schema import RSTStreamFrame as Schema_RSTStreamFrame
104
+ from pcapkit.protocols.application.httpv2.schema import SettingPair as Schema_SettingPair
105
+ from pcapkit.protocols.application.httpv2.schema import SettingsFrame as Schema_SettingsFrame
106
+ from pcapkit.protocols.application.httpv2.schema import UnassignedFrame as Schema_UnassignedFrame
107
+ from pcapkit.protocols.application.httpv2.schema import \
108
+ WindowUpdateFrame as Schema_WindowUpdateFrame
109
+ from pcapkit.protocols.schema import Schema
110
+ from pcapkit.utilities.exceptions import ProtocolError
111
+ from pcapkit.utilities.warnings import ProtocolWarning, RegistryWarning, warn
112
+
113
+ if TYPE_CHECKING:
114
+ from typing import Any, Callable, DefaultDict, Optional, Tuple
115
+
116
+ from mypy_extensions import DefaultArg, KwArg, NamedArg
117
+ from typing_extensions import Literal
118
+
119
+ from pcapkit.protocols.protocol import ProtocolBase
120
+
121
+ Flags = Schema_FrameType.Flags
122
+
123
+ FrameParser = Callable[[Schema_FrameType, NamedArg(Schema_HTTP, 'header')], Data_HTTP]
124
+ # NB: ``Flags`` is bound just above, so it goes in unquoted. Quoted, it would
125
+ # leave a bare ``ForwardRef('Flags')`` in the alias, which another module
126
+ # annotating with ``FrameConstructor`` cannot resolve in its own namespace.
127
+ FrameConstructor = Callable[[DefaultArg(Optional[Data_HTTP]),
128
+ KwArg(Any)], Tuple[Schema_FrameType, Flags]]
129
+
130
+ __all__ = ['HTTPv2']
131
+
132
+
133
+ def _opens_whole_frame(data: 'bytes') -> 'bool':
134
+ """Whether ``data`` opens with a whole HTTP/2 frame.
135
+
136
+ Only the 9-octet frame header is read: the frame is whole when its Length,
137
+ which counts the frame payload alone (:rfc:`9113#section-4.1`), ends inside
138
+ ``data``. The type, flags and stream are left to :meth:`HTTPv2.read`, so a
139
+ whole frame it refuses is kept with its error.
140
+
141
+ Args:
142
+ data: Octets after a frame.
143
+
144
+ Returns:
145
+ Whether a further frame opens ``data`` and ends inside it.
146
+
147
+ """
148
+ return len(data) >= 9 and 9 + int.from_bytes(data[:3], 'big') <= len(data)
149
+
150
+
151
+ class HTTPv2(HTTPBase[Data_HTTP, Schema_HTTP],
152
+ schema=Schema_HTTP, data=Data_HTTP):
153
+ """This class implements Hypertext Transfer Protocol (HTTP/2).
154
+
155
+ The HTTP/2 frames it parses, by :class:`pcapkit.const.http.frame.Frame` type:
156
+
157
+ .. list-table::
158
+ :header-rows: 1
159
+
160
+ * - Frame Code
161
+ - Frame Parser
162
+ - Frame Constructor
163
+ * - :attr:`~pcapkit.const.http.frame.Frame.DATA`
164
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_data`
165
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_data`
166
+ * - :attr:`~pcapkit.const.http.frame.Frame.HEADERS`
167
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_headers`
168
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_headers`
169
+ * - :attr:`~pcapkit.const.http.frame.Frame.PRIORITY`
170
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_priority`
171
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_priority`
172
+ * - :attr:`~pcapkit.const.http.frame.Frame.RST_STREAM`
173
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_rst_stream`
174
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_rst_stream`
175
+ * - :attr:`~pcapkit.const.http.frame.Frame.SETTINGS`
176
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_settings`
177
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_settings`
178
+ * - :attr:`~pcapkit.const.http.frame.Frame.PUSH_PROMISE`
179
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_push_promise`
180
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_push_promise`
181
+ * - :attr:`~pcapkit.const.http.frame.Frame.PING`
182
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_ping`
183
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_ping`
184
+ * - :attr:`~pcapkit.const.http.frame.Frame.GOAWAY`
185
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_goaway`
186
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_goaway`
187
+ * - :attr:`~pcapkit.const.http.frame.Frame.WINDOW_UPDATE`
188
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_window_update`
189
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_window_update`
190
+ * - :attr:`~pcapkit.const.http.frame.Frame.CONTINUATION`
191
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._read_http_continuation`
192
+ - :meth:`~pcapkit.protocols.application.httpv2.protocol.HTTPv2._make_http_continuation`
193
+
194
+ .. versionchanged:: 1.6.0
195
+
196
+ * A payload opening with the connection preface parses, with the preface
197
+ kept as ``preface`` and counted in :attr:`length`, and :meth:`make`
198
+ takes ``preface``, since a dispatched HTTP/2 payload reaches this class
199
+ rather than :class:`~pcapkit.protocols.application.http.protocol.HTTP`
200
+ (:issue:`2524`).
201
+ * A whole frame after the first in a segment is a further layer of this
202
+ class, where it was kept as :class:`~pcapkit.protocols.misc.raw.protocol.Raw`
203
+ (:issue:`2536`).
204
+ * A ``SETTINGS`` frame the capture cut inside its settings parses, with the
205
+ setting the cut lands inside read as zeros past it, as a cut ``DATA``
206
+ frame's data is, and no setting past the data, where it was
207
+ :class:`~pcapkit.protocols.misc.raw.protocol.Raw` (:issue:`2659`,
208
+ :issue:`2686`, :issue:`2756`).
209
+ * Each enumeration field of :meth:`make` and of the frame makers takes
210
+ a member or an :class:`int` code, resolved with the enumeration's
211
+ ``get``; a name, a :obj:`bool` for a field wider than one bit, or a
212
+ code the field cannot carry raises
213
+ :exc:`~pcapkit.utilities.exceptions.ProtocolError`, rather than
214
+ resolving against an enumeration inferred from the caller's frame or
215
+ writing a different value (:issue:`2594`).
216
+
217
+ .. versionremoved:: 1.6.0
218
+
219
+ The ``type_default``, ``type_namespace`` and ``type_reversed``
220
+ arguments of :meth:`make`, and the ``error_default``,
221
+ ``error_namespace`` and ``error_reversed`` arguments of the
222
+ ``RST_STREAM`` and ``GOAWAY`` frame makers; resolve a name with
223
+ :meth:`~pcapkit.protocols.protocol.Protocol.resolve_index` first
224
+ (:issue:`2594`).
225
+
226
+ """
227
+
228
+ ##########################################################################
229
+ # Defaults.
230
+ ##########################################################################
231
+
232
+ #: Frame code to method mapping. A :obj:`str` value names the
233
+ #: ``_read_http_${name}`` and ``_make_http_${name}`` methods, which fall back
234
+ #: to ``_read_http_none`` and ``_make_http_none`` when not defined, as an
235
+ #: unregistered code does; any other value is a ``(parser, constructor)``
236
+ #: pair of callables.
237
+ __frame__ = collections.defaultdict(
238
+ lambda: 'none',
239
+ {
240
+ Enum_Frame.DATA: 'data', # DATA
241
+ Enum_Frame.HEADERS: 'headers', # HEADERS
242
+ Enum_Frame.PRIORITY: 'priority', # PRIORITY
243
+ Enum_Frame.RST_STREAM: 'rst_stream', # RST_STREAM
244
+ Enum_Frame.SETTINGS: 'settings', # SETTINGS
245
+ Enum_Frame.PUSH_PROMISE: 'push_promise', # PUSH_PROMISE
246
+ Enum_Frame.PING: 'ping', # PING
247
+ Enum_Frame.GOAWAY: 'goaway', # GOAWAY
248
+ Enum_Frame.WINDOW_UPDATE: 'window_update', # WINDOW_UPDATE
249
+ Enum_Frame.CONTINUATION: 'continuation', # CONTINUATION
250
+ },
251
+ ) # type: DefaultDict[Enum_Frame | int, str | tuple[FrameParser, FrameConstructor]]
252
+
253
+ ##########################################################################
254
+ # Properties.
255
+ ##########################################################################
256
+
257
+ @property
258
+ def alias(self) -> 'Literal["HTTP/2"]':
259
+ """Acronym of current protocol."""
260
+ return 'HTTP/2'
261
+
262
+ @property
263
+ def length(self) -> 'int':
264
+ """Header length of current protocol -- the 9-octet frame header, after the
265
+ 24-octet connection preface when one opens the payload."""
266
+ return 9 + self._preface_length
267
+
268
+ @property
269
+ def version(self) -> 'Literal["2"]':
270
+ """Version of current protocol."""
271
+ return '2'
272
+
273
+ ##########################################################################
274
+ # Methods.
275
+ ##########################################################################
276
+
277
+ def unpack(self, length: 'Optional[int]' = None, **kwargs: 'Any') -> 'Data_HTTP':
278
+ """Unpack (parse) packet data.
279
+
280
+ Args:
281
+ length: Length of packet data.
282
+ **kwargs: Arbitrary keyword arguments.
283
+
284
+ Returns:
285
+ Parsed packet data.
286
+
287
+ Raises:
288
+ ProtocolError: If the packet is malformed.
289
+
290
+ Notes:
291
+ This guards ahead of :meth:`Schema.unpack
292
+ <pcapkit.protocols.schema.Schema.unpack>` rather than
293
+ leaving the check to :meth:`read`, because a buffer shorter than the
294
+ fixed 9-octet header cannot be parsed meaningfully.
295
+ ``pkt['__length__']`` there is decremented by each field's
296
+ *nominal* width regardless of how many octets the buffer had, so it
297
+ goes negative and the frame payload's length-derived fields (e.g. an
298
+ unpadded ``DATA`` frame's ``data: BytesField(length=lambda pkt:
299
+ pkt['__length__'])``) resolve to a negative width. Rejecting here
300
+ keeps such a frame from reaching that arithmetic. An inner field can
301
+ still drive it negative on a buffer that clears nine (e.g. a
302
+ ``GOAWAY`` frame at 9-16 octets, whose fixed ``stream`` and
303
+ ``error`` fields alone consume eight); the schema layer raises
304
+ :exc:`~pcapkit.utilities.exceptions.ProtocolError` for that itself.
305
+
306
+ ``length`` is resolved against :func:`len` only for *this*
307
+ method's own check, and the *original* argument -- ``None``
308
+ included -- is what is forwarded to :meth:`Protocol.unpack
309
+ <pcapkit.protocols.protocol.Protocol.unpack>`. Collapsing
310
+ ``None`` to a concrete ``0`` would change what
311
+ :meth:`Schema.unpack <pcapkit.protocols.schema.Schema.unpack>`'s own
312
+ ``prepare`` decorator does with an
313
+ exhausted stream: it raises
314
+ :exc:`~pcapkit.utilities.exceptions.StreamEOFError` (an
315
+ :exc:`EOFError`, the documented "no more packets" signal) only when
316
+ the *caller* left ``length`` unspecified, and a resolved ``0``
317
+ would report an exhausted stream as a malformed packet. A
318
+ *non-zero* short buffer is malformed either way, so it is rejected
319
+ here whether or not ``length`` was given.
320
+
321
+ A payload opening with the HTTP/2 connection preface
322
+ (:rfc:`9113#section-3.4`) has the frame parsed from the octets after
323
+ it, as :meth:`HTTP._guess_version
324
+ <pcapkit.protocols.application.http.protocol.HTTP._guess_version>` parses it,
325
+ since a dispatched payload reaches this class rather than that one
326
+ (:issue:`2524`); the preface counts towards :attr:`length`. A
327
+ preface with no frame after it is refused, since the data model
328
+ holds one frame per packet and has no form for a frameless segment.
329
+
330
+ """
331
+ preface_len = len(_HTTP2_PREFACE)
332
+ if self.__header__ is None and self._data[:preface_len] == _HTTP2_PREFACE \
333
+ and (length is None or length >= preface_len):
334
+ remaining = (len(self) if length is None else length) - preface_len
335
+ if remaining == 0:
336
+ raise ProtocolError('HTTP/2: connection preface with no frame')
337
+ self._preface_length = preface_len
338
+ self._file.seek(preface_len)
339
+ length = remaining
340
+
341
+ if length is None:
342
+ # ``0 <``: an exhausted stream is left for ``Protocol.unpack``'s
343
+ # ``prepare`` decorator to raise ``StreamEOFError``, as documented
344
+ # above; only a non-empty short stream is malformed.
345
+ if 0 < len(self) < 9:
346
+ raise ProtocolError(f'HTTP/2: invalid format, packet ({len(self)} octet(s)) '
347
+ f'shorter than the 9-octet frame header')
348
+ elif length < 9:
349
+ # An explicit length, zero included, asserts how much data the
350
+ # frame has, so every value under nine is malformed.
351
+ raise ProtocolError(f'HTTP/2: invalid format, packet ({length} octet(s)) '
352
+ f'shorter than the 9-octet frame header')
353
+ return super().unpack(length, **kwargs)
354
+
355
+ def read(self, length: 'Optional[int]' = None, **kwargs: 'Any') -> 'Data_HTTP':
356
+ """Read Hypertext Transfer Protocol (HTTP/2).
357
+
358
+ Structure of HTTP/2 packet [:rfc:`7540`]:
359
+
360
+ .. code-block:: text
361
+
362
+ +-----------------------------------------------+
363
+ | Length (24) |
364
+ +---------------+---------------+---------------+
365
+ | Type (8) | Flags (8) |
366
+ +-+-------------+---------------+-------------------------------+
367
+ |R| Stream Identifier (31) |
368
+ +=+=============================================================+
369
+ | Frame Payload (0...) ...
370
+ +---------------------------------------------------------------+
371
+
372
+ Args:
373
+ length: Length of packet data.
374
+ **kwargs: Arbitrary keyword arguments.
375
+
376
+ Returns:
377
+ Parsed packet data.
378
+
379
+ Raises:
380
+ ProtocolError: If the packet is malformed.
381
+
382
+ """
383
+ if length is None:
384
+ length = len(self) - self._preface_length
385
+ schema = self.__header__
386
+
387
+ # NOTE: ``schema.length`` counts the payload alone (RFC 9113, section 4.1), so
388
+ # ``length`` must cover the 9-octet header and the declared payload as well.
389
+ if length < 9 or schema.length + 9 > length:
390
+ raise ProtocolError(f'HTTP/2: [Type {schema.type}] invalid format')
391
+ if schema.type in (Enum_Frame.SETTINGS, Enum_Frame.PING) and schema.stream['sid'] != 0:
392
+ raise ProtocolError(f'HTTP/2: [Type {schema.type}] invalid format')
393
+
394
+ name = self._lookup_registry(self.__frame__, schema.type)
395
+ if isinstance(name, str):
396
+ meth_name = f'_read_http_{name}'
397
+ meth = cast('FrameParser',
398
+ getattr(self, meth_name, self._read_http_none))
399
+ else:
400
+ meth = name[0]
401
+ http = meth(schema.frame, header=schema)
402
+ if self._preface_length:
403
+ http.__update__({
404
+ 'preface': _HTTP2_PREFACE,
405
+ })
406
+
407
+ # The frame ends at its declared Length; what follows it is a further
408
+ # whole frame, dissected as one, or else the undissected remainder (#2536).
409
+ return self._decode_next_layer(http, -1, length - 9 - schema.length)
410
+
411
+ def make(self, # type: ignore[override]
412
+ type: 'Enum_Frame | int' = Enum_Frame.DATA,
413
+ flags: 'Flags' = 0, # type: ignore[assignment]
414
+ reserved: 'int' = 0,
415
+ sid: 'int' = 0,
416
+ frame: 'Optional[bytes | Data_HTTP | Schema_FrameType | dict[str, Any]]' = None,
417
+ payload: 'bytes | ProtocolBase | Schema' = b'',
418
+ preface: 'bool' = False, # pylint: disable=unused-argument
419
+ **kwargs: 'Any') -> 'Schema_HTTP':
420
+ """Make (construct) packet data.
421
+
422
+ Args:
423
+ type: Type of HTTP/2 frame.
424
+ flags: Flags of HTTP/2 frame, combined with those the frame
425
+ constructor derives from ``frame``.
426
+ reserved: Reserved bit of the frame header.
427
+ sid: Stream ID of HTTP/2 frame.
428
+ frame: Frame data of HTTP/2 frame. Omitted (:data:`None`), the frame
429
+ type's own default payload is built, as for ``{}``; a
430
+ :obj:`bytes` value, ``b''`` included, is packed as raw octets.
431
+ payload: Octets after the frame, e.g. the next frame.
432
+ preface: Whether the HTTP/2 connection preface goes ahead of the
433
+ frame; :meth:`pack` writes it.
434
+ **kwargs: Arbitrary keyword arguments.
435
+
436
+ Returns:
437
+ Constructed packet data.
438
+
439
+ Raises:
440
+ ProtocolError: If ``type`` is a name, a :obj:`bool`, or a member
441
+ or code the 8-bit Type field cannot carry; or if ``frame`` is
442
+ none of the forms this maker reads -- raw :obj:`bytes`, a
443
+ :obj:`dict` of frame arguments, an
444
+ :class:`~pcapkit.protocols.application.httpv2.data.HTTPv2` data
445
+ model or a :class:`~pcapkit.protocols.schema.Schema`.
446
+
447
+ .. versionchanged:: 1.5.0
448
+
449
+ * ``reserved`` is a new parameter before ``sid``, so a 1.4.x
450
+ positional argument meant for ``sid`` or ``frame`` lands one
451
+ parameter early (:issue:`1246`).
452
+ * ``frame`` defaults to :data:`None` and dispatches to the frame
453
+ type's constructor, since the former ``b''`` default is shorter
454
+ than the payload a frame type of fixed or minimum size needs, so
455
+ such a frame could not be built at all (:issue:`2274`).
456
+
457
+ """
458
+ type_val = self._make_index(type, Enum_Frame, bits=8, name='type')
459
+
460
+ if frame is None:
461
+ # An omitted frame dispatches to the type's own constructor, as
462
+ # ``{}`` does, since a fixed-size payload cannot be empty octets
463
+ # (#2274). An explicit ``b''`` stays raw.
464
+ frame = {}
465
+
466
+ if isinstance(frame, bytes):
467
+ frame_val = frame # type: bytes | Schema_FrameType
468
+ elif isinstance(frame, (dict, Data_HTTP)):
469
+ name = self._lookup_registry(self.__frame__, type_val)
470
+ if isinstance(name, str):
471
+ meth_name = f'_make_http_{name}'
472
+ meth = cast('FrameConstructor',
473
+ getattr(self, meth_name, self._make_http_none))
474
+ else:
475
+ meth = name[1]
476
+
477
+ if isinstance(frame, dict):
478
+ frame_val, frame_flags = meth(**frame)
479
+ else:
480
+ frame_val, frame_flags = meth(frame)
481
+ flags = cast('Flags', int(flags) | int(frame_flags))
482
+ elif isinstance(frame, Schema):
483
+ frame_val = frame
484
+ else:
485
+ raise ProtocolError(f'HTTP/2: [Type {type_val}] invalid frame: must be bytes, a dict, '
486
+ f'an HTTP data model or a Schema, not {frame!r}')
487
+
488
+ flags_val = {} # type: dict[str, int]
489
+ for bit in range(8):
490
+ flags_val[f'bit_{bit}'] = (int(flags) & (1 << bit)) >> bit
491
+
492
+ length = self._make_http_length(frame_val, flags)
493
+
494
+ return Schema_HTTP(
495
+ length=length,
496
+ type=type_val,
497
+ flags=flags_val, # type: ignore[arg-type]
498
+ stream={
499
+ 'reserved': reserved,
500
+ 'sid': sid,
501
+ },
502
+ frame=frame_val,
503
+ payload=payload,
504
+ )
505
+
506
+ def pack(self, **kwargs: 'Any') -> 'bytes':
507
+ """Pack (construct) packet data.
508
+
509
+ Args:
510
+ **kwargs: Arbitrary keyword arguments.
511
+
512
+ Returns:
513
+ Constructed packet data.
514
+
515
+ Notes:
516
+ :meth:`make` takes the frame payload as raw octets or as a built
517
+ frame schema as well, and neither carries what the frame readers
518
+ need, e.g. ``__flags__``. So while the instance is being
519
+ constructed, the header :meth:`make` returns is dropped once packed,
520
+ and :meth:`unpack` parses the packed octets back with the frame
521
+ type's own schema. Any other call leaves the instance's header as it
522
+ was (:issue:`1769`).
523
+
524
+ """
525
+ data = super().pack(**kwargs)
526
+ # NOTE: Constructing, by the test ``ProtocolBase._packing_target`` makes.
527
+ if '_info' not in vars(self):
528
+ self.__header__ = None # type: ignore[assignment]
529
+ return data
530
+
531
+ @classmethod
532
+ def id(cls) -> 'tuple[Literal["HTTP/2"]]': # type: ignore[override]
533
+ """Index ID of the protocol.
534
+
535
+ :rfc:`9113` names the protocol ``HTTP/2``.
536
+
537
+ Returns:
538
+ Index ID of the protocol.
539
+
540
+ .. versionchanged:: 1.6.0
541
+
542
+ ``('HTTP/2',)``, narrowed to this class, where it was
543
+ ``('HTTP', 'HTTPv2')`` (:issue:`2524`).
544
+
545
+ """
546
+ return ('HTTP/2',)
547
+
548
+ @classmethod
549
+ def register_frame(cls, code: 'Enum_Frame', meth: 'str | tuple[FrameParser, FrameConstructor]') -> 'None':
550
+ """Register a frame parser.
551
+
552
+ Args:
553
+ code: HTTP frame type code.
554
+ meth: Name of the ``_read_http_${name}`` and ``_make_http_${name}``
555
+ methods, or a ``(parser, constructor)`` pair of callables; see
556
+ :attr:`__frame__`.
557
+
558
+ Warns:
559
+ RegistryWarning: If a different entry is already registered for
560
+ ``code``; it is overwritten. Handing back the entry already
561
+ stored, or one equal to it, is a silent no-op. The entry
562
+ ``code`` shipped with is accepted like any other, so an
563
+ override can be undone (:issue:`1362`, :issue:`1363`).
564
+
565
+ """
566
+ incumbent = cls.__frame__.get(code)
567
+ if incumbent is not None and incumbent == meth:
568
+ return
569
+ if incumbent is not None:
570
+ warn(f'HTTP/2: [Type {code}] frame already registered', RegistryWarning)
571
+ cls.__frame__[code] = meth
572
+
573
+ ##########################################################################
574
+ # Data models.
575
+ ##########################################################################
576
+
577
+ def __length_hint__(self) -> 'Literal[9]':
578
+ """Return an estimated length for the object."""
579
+ return 9
580
+
581
+ ##########################################################################
582
+ # Utilities.
583
+ ##########################################################################
584
+
585
+ @classmethod
586
+ def _make_data(cls, data: 'Data_HTTP') -> 'dict[str, Any]': # type: ignore[override]
587
+ """Create key-value pairs from ``data`` for protocol construction.
588
+
589
+ Args:
590
+ data: protocol data
591
+
592
+ Returns:
593
+ Key-value pairs for protocol construction.
594
+
595
+ """
596
+ # NOTE: No ``length``: ``make`` computes the Length from the frame it builds, and
597
+ # ``ProtocolBase.__init__`` would take a ``length`` as the octets to parse back.
598
+ return {
599
+ 'type': data.type,
600
+ 'flags': data.flags.__value__ if data.flags is not None else 0,
601
+ 'reserved': data.reserved,
602
+ 'sid': data.sid,
603
+ 'frame': data,
604
+ 'payload': cls._make_payload(data),
605
+ 'preface': bool(data.get('preface')),
606
+ }
607
+
608
+ @staticmethod
609
+ def _make_http_length(frame: 'bytes | Schema_FrameType', flags: 'Flags') -> 'int':
610
+ """Calculate HTTP/2 frame payload length for construction.
611
+
612
+ Several frame payload schemas use conditional fields keyed by the
613
+ containing HTTP/2 header flags, so packing them without that context can
614
+ produce incorrect lengths or fail outright.
615
+ """
616
+ if isinstance(frame, bytes):
617
+ return len(frame)
618
+
619
+ flags_int = int(flags)
620
+ if isinstance(frame, Schema_UnassignedFrame):
621
+ return len(frame.data)
622
+ if isinstance(frame, Schema_DataFrame):
623
+ padded = flags_int & int(Schema_DataFrame.Flags.PADDED)
624
+ return len(frame.data) + ((frame.pad_len or 0) + 1 if padded else 0)
625
+ if isinstance(frame, Schema_HeadersFrame):
626
+ padded = flags_int & int(Schema_HeadersFrame.Flags.PADDED)
627
+ priority_len = 5 if flags_int & int(Schema_HeadersFrame.Flags.PRIORITY) else 0
628
+ return len(frame.fragment) + priority_len + ((frame.pad_len or 0) + 1 if padded else 0)
629
+ if isinstance(frame, Schema_PriorityFrame):
630
+ return 5
631
+ if isinstance(frame, Schema_RSTStreamFrame):
632
+ return 4
633
+ if isinstance(frame, Schema_SettingsFrame):
634
+ settings = cast('object', frame.settings)
635
+ if isinstance(settings, bytes):
636
+ return len(settings)
637
+ return len(frame.settings) * 6
638
+ if isinstance(frame, Schema_PushPromiseFrame):
639
+ padded = flags_int & int(Schema_PushPromiseFrame.Flags.PADDED)
640
+ return len(frame.fragment) + 4 + ((frame.pad_len or 0) + 1 if padded else 0)
641
+ if isinstance(frame, Schema_PingFrame):
642
+ return 8
643
+ if isinstance(frame, Schema_GoawayFrame):
644
+ return len(frame.debug) + 8
645
+ if isinstance(frame, Schema_WindowUpdateFrame):
646
+ return 4
647
+ if isinstance(frame, Schema_ContinuationFrame):
648
+ return len(frame.fragment)
649
+ return len(frame.pack())
650
+
651
+ def _read_http_none(self, schema: 'Schema_UnassignedFrame', *,
652
+ header: 'Schema_HTTP') -> 'Data_UnassignedFrame':
653
+ """Read HTTP packet with unassigned type.
654
+
655
+ Args:
656
+ schema: Parsed frame schema.
657
+ header: Parsed HTTP/2 header schema.
658
+
659
+ Returns:
660
+ Parsed packet data.
661
+
662
+ """
663
+ if any(header.flags.values()):
664
+ warn(f'HTTP/2: [Type {header.type}] invalid format', ProtocolWarning)
665
+
666
+ data = Data_UnassignedFrame(
667
+ length=header.length,
668
+ type=header.type,
669
+ flags=self._read_http_flags(schema),
670
+ reserved=header.stream['reserved'],
671
+ sid=header.stream['sid'],
672
+ data=schema.data,
673
+ )
674
+ return data
675
+
676
+ def _read_http_data(self, schema: 'Schema_DataFrame', *,
677
+ header: 'Schema_HTTP') -> 'Data_DataFrame':
678
+ """Read HTTP/2 ``DATA`` frames.
679
+
680
+ Structure of HTTP/2 ``DATA`` frame [:rfc:`7540`]:
681
+
682
+ .. code-block:: text
683
+
684
+ +-----------------------------------------------+
685
+ | Length (24) |
686
+ +---------------+---------------+---------------+
687
+ | Type (8) | Flags (8) |
688
+ +-+-------------+---------------+-------------------------------+
689
+ |R| Stream Identifier (31) |
690
+ +---------------+-----------------------------------------------+
691
+ |Pad Length? (8)|
692
+ +---------------+-----------------------------------------------+
693
+ | Data (*) ...
694
+ +---------------------------------------------------------------+
695
+ | Padding (*) ...
696
+ +---------------------------------------------------------------+
697
+
698
+ Args:
699
+ schema: Parsed frame schema.
700
+ header: Parsed HTTP/2 header schema.
701
+
702
+ Returns:
703
+ Parsed packet data.
704
+
705
+ """
706
+ flag = Data_DataFrameFlags(
707
+ END_STREAM=bool(header.flags['bit_0']), # bit 0
708
+ PADDED=bool(header.flags['bit_3']), # bit 3
709
+ )
710
+ flag.__update__({
711
+ '__value__': schema.__flags__,
712
+ })
713
+
714
+ data = Data_DataFrame(
715
+ length=header.length,
716
+ type=header.type,
717
+ flags=flag,
718
+ pad_len=schema.pad_len if flag.PADDED else 0,
719
+ reserved=header.stream['reserved'],
720
+ sid=header.stream['sid'],
721
+ data=schema.data,
722
+ padding=schema.padding if flag.PADDED else b'',
723
+ )
724
+ return data
725
+
726
+ def _read_http_headers(self, schema: 'Schema_HeadersFrame', *,
727
+ header: 'Schema_HTTP') -> 'Data_HeadersFrame':
728
+ """Read HTTP/2 ``HEADERS`` frames.
729
+
730
+ Structure of HTTP/2 ``HEADERS`` frame [:rfc:`7540`]:
731
+
732
+ .. code-block:: text
733
+
734
+ +-----------------------------------------------+
735
+ | Length (24) |
736
+ +---------------+---------------+---------------+
737
+ | Type (8) | Flags (8) |
738
+ +-+-------------+---------------+-------------------------------+
739
+ |R| Stream Identifier (31) |
740
+ +---------------+-----------------------------------------------+
741
+ |Pad Length? (8)|
742
+ +-+-------------+-----------------------------------------------+
743
+ |E| Stream Dependency? (31) |
744
+ +-+-------------+-----------------------------------------------+
745
+ | Weight? (8) |
746
+ +-+-------------+-----------------------------------------------+
747
+ | Header Block Fragment (*) ...
748
+ +---------------------------------------------------------------+
749
+ | Padding (*) ...
750
+ +---------------------------------------------------------------+
751
+
752
+ Args:
753
+ schema: Parsed frame schema.
754
+ header: Parsed HTTP/2 header schema.
755
+
756
+ Returns:
757
+ Parsed packet data.
758
+
759
+ """
760
+ flag = Data_HeadersFrameFlags(
761
+ END_STREAM=bool(header.flags['bit_0']), # bit 0
762
+ END_HEADERS=bool(header.flags['bit_2']), # bit 2
763
+ PADDED=bool(header.flags['bit_3']), # bit 3
764
+ PRIORITY=bool(header.flags['bit_5']), # bit 5
765
+ )
766
+ flag.__update__({
767
+ '__value__': schema.__flags__,
768
+ })
769
+
770
+ data = Data_HeadersFrame(
771
+ length=header.length,
772
+ type=header.type,
773
+ flags=flag,
774
+ pad_len=schema.pad_len if flag.PADDED else 0,
775
+ reserved=header.stream['reserved'],
776
+ sid=header.stream['sid'],
777
+ excl_dependency=bool(schema.stream_dep['exclusive']) if flag.PRIORITY else False,
778
+ stream_dependency=schema.stream_dep['sid'] if flag.PRIORITY else 0,
779
+ weight=(schema.weight + 1) if flag.PRIORITY else 0,
780
+ fragment=schema.fragment,
781
+ padding=schema.padding if flag.PADDED else b'',
782
+ )
783
+ return data
784
+
785
+ def _read_http_priority(self, schema: 'Schema_PriorityFrame', *,
786
+ header: 'Schema_HTTP') -> 'Data_PriorityFrame': # pylint: disable=unused-argument
787
+ """Read HTTP/2 ``PRIORITY`` frames.
788
+
789
+ Structure of HTTP/2 ``PRIORITY`` frame [:rfc:`7540`]:
790
+
791
+ .. code-block:: text
792
+
793
+ +-----------------------------------------------+
794
+ | Length (24) |
795
+ +---------------+---------------+---------------+
796
+ | Type (8) | Flags (8) |
797
+ +-+-------------+---------------+-------------------------------+
798
+ |R| Stream Identifier (31) |
799
+ +-+-------------------------------------------------------------+
800
+ |E| Stream Dependency (31) |
801
+ +-+-------------+-----------------------------------------------+
802
+ | Weight (8) |
803
+ +-+-------------+
804
+
805
+ Args:
806
+ schema: Parsed frame schema.
807
+ header: Parsed HTTP/2 header schema.
808
+
809
+ Returns:
810
+ Parsed packet data.
811
+
812
+ Raises:
813
+ ProtocolError: If the packet is malformed.
814
+
815
+ """
816
+ if header.length != 5:
817
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
818
+
819
+ data = Data_PriorityFrame(
820
+ length=header.length,
821
+ type=header.type,
822
+ flags=self._read_http_flags(schema),
823
+ reserved=header.stream['reserved'],
824
+ sid=header.stream['sid'],
825
+ excl_dependency=bool(schema.stream['exclusive']),
826
+ stream_dependency=schema.stream['sid'],
827
+ weight=schema.weight + 1,
828
+ )
829
+ return data
830
+
831
+ def _read_http_rst_stream(self, schema: 'Schema_RSTStreamFrame', *,
832
+ header: 'Schema_HTTP') -> 'Data_RSTStreamFrame': # pylint: disable=unused-argument
833
+ """Read HTTP/2 ``RST_STREAM`` frames.
834
+
835
+ Structure of HTTP/2 ``RST_STREAM`` frame [:rfc:`7540`]:
836
+
837
+ .. code-block:: text
838
+
839
+ +-----------------------------------------------+
840
+ | Length (24) |
841
+ +---------------+---------------+---------------+
842
+ | Type (8) | Flags (8) |
843
+ +-+-------------+---------------+-------------------------------+
844
+ |R| Stream Identifier (31) |
845
+ +---------------------------------------------------------------+
846
+ | Error Code (32) |
847
+ +---------------------------------------------------------------+
848
+
849
+ Args:
850
+ schema: Parsed frame schema.
851
+ header: Parsed HTTP/2 header schema.
852
+
853
+ Returns:
854
+ Parsed packet data.
855
+
856
+ Raises:
857
+ ProtocolError: If the packet is malformed.
858
+
859
+ """
860
+ if header.length != 4:
861
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
862
+
863
+ data = Data_RSTStreamFrame(
864
+ length=header.length,
865
+ type=header.type,
866
+ flags=self._read_http_flags(schema),
867
+ reserved=header.stream['reserved'],
868
+ sid=header.stream['sid'],
869
+ error=schema.error,
870
+ )
871
+ return data
872
+
873
+ def _read_http_settings(self, schema: 'Schema_SettingsFrame', *,
874
+ header: 'Schema_HTTP') -> 'Data_SettingsFrame':
875
+ """Read HTTP/2 ``SETTINGS`` frames.
876
+
877
+ Structure of HTTP/2 ``SETTINGS`` frame [:rfc:`7540`]:
878
+
879
+ .. code-block:: text
880
+
881
+ +-----------------------------------------------+
882
+ | Length (24) |
883
+ +---------------+---------------+---------------+
884
+ | Type (8) | Flags (8) |
885
+ +-+-------------+---------------+-------------------------------+
886
+ |R| Stream Identifier (31) |
887
+ +---------------------------------------------------------------+
888
+ | Identifier (16) |
889
+ +-------------------------------+-------------------------------+
890
+ | Value (32) |
891
+ +---------------------------------------------------------------+
892
+ | ...... |
893
+
894
+ Args:
895
+ schema: Parsed frame schema.
896
+ header: Parsed HTTP/2 header schema.
897
+
898
+ Returns:
899
+ Parsed packet data.
900
+
901
+ Raises:
902
+ ProtocolError: If the packet is malformed.
903
+
904
+ """
905
+ if header.length % 6 != 0 or header.stream['sid'] != 0:
906
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
907
+
908
+ flag = Data_SettingsFrameFlags(
909
+ ACK=bool(header.flags['bit_0']), # bit 0
910
+ )
911
+ flag.__update__({
912
+ '__value__': schema.__flags__,
913
+ })
914
+
915
+ if flag.ACK and header.length != 0:
916
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
917
+
918
+ # NOTE: Every pair, not a mapping: an identifier may repeat and applies in order
919
+ # (:rfc:`9113#section-6.5.3`); ``Settings`` answers an index with the last value.
920
+ sets = Data_Settings([(setting.id, setting.value) for setting in schema.settings])
921
+
922
+ data = Data_SettingsFrame(
923
+ length=header.length,
924
+ type=header.type,
925
+ flags=flag,
926
+ reserved=header.stream['reserved'],
927
+ sid=header.stream['sid'],
928
+ settings=sets,
929
+ )
930
+ return data
931
+
932
+ def _read_http_push_promise(self, schema: 'Schema_PushPromiseFrame', *,
933
+ header: 'Schema_HTTP') -> 'Data_PushPromiseFrame':
934
+ """Read HTTP/2 ``PUSH_PROMISE`` frames.
935
+
936
+ Structure of HTTP/2 ``PUSH_PROMISE`` frame [:rfc:`7540`]:
937
+
938
+ .. code-block:: text
939
+
940
+ +-----------------------------------------------+
941
+ | Length (24) |
942
+ +---------------+---------------+---------------+
943
+ | Type (8) | Flags (8) |
944
+ +-+-------------+---------------+-------------------------------+
945
+ |R| Stream Identifier (31) |
946
+ +---------------+-----------------------------------------------+
947
+ |Pad Length? (8)|
948
+ +-+-------------+-----------------------------------------------+
949
+ |R| Promised Stream ID (31) |
950
+ +-+-----------------------------+-------------------------------+
951
+ | Header Block Fragment (*) ...
952
+ +---------------------------------------------------------------+
953
+ | Padding (*) ...
954
+ +---------------------------------------------------------------+
955
+
956
+ Args:
957
+ schema: Parsed frame schema.
958
+ header: Parsed HTTP/2 header schema.
959
+
960
+ Returns:
961
+ Parsed packet data.
962
+
963
+ Raises:
964
+ ProtocolError: If the packet is malformed.
965
+
966
+ """
967
+ if header.length < 4:
968
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
969
+
970
+ flag = Data_PushPromiseFrameFlags(
971
+ END_HEADERS=bool(header.flags['bit_2']), # bit 2
972
+ PADDED=bool(header.flags['bit_3']), # bit 3
973
+ )
974
+ flag.__update__({
975
+ '__value__': schema.__flags__,
976
+ })
977
+
978
+ data = Data_PushPromiseFrame(
979
+ length=header.length,
980
+ type=header.type,
981
+ flags=flag,
982
+ reserved=header.stream['reserved'],
983
+ sid=header.stream['sid'],
984
+ pad_len=schema.pad_len if flag.PADDED else 0,
985
+ promised_reserved=schema.stream['reserved'],
986
+ promised_sid=schema.stream['sid'],
987
+ fragment=schema.fragment,
988
+ padding=schema.padding if flag.PADDED else b'',
989
+ )
990
+
991
+ return data
992
+
993
+ def _read_http_ping(self, schema: 'Schema_PingFrame', *,
994
+ header: 'Schema_HTTP') -> 'Data_PingFrame':
995
+ """Read HTTP/2 ``PING`` frames.
996
+
997
+ Structure of HTTP/2 ``PING`` frame [:rfc:`7540`]:
998
+
999
+ .. code-block:: text
1000
+
1001
+ +-----------------------------------------------+
1002
+ | Length (24) |
1003
+ +---------------+---------------+---------------+
1004
+ | Type (8) | Flags (8) |
1005
+ +-+-------------+---------------+-------------------------------+
1006
+ |R| Stream Identifier (31) |
1007
+ +---------------------------------------------------------------+
1008
+ | |
1009
+ | Opaque Data (64) |
1010
+ | |
1011
+ +---------------------------------------------------------------+
1012
+
1013
+ Args:
1014
+ schema: Parsed frame schema.
1015
+ header: Parsed HTTP/2 header schema.
1016
+
1017
+ Returns:
1018
+ Parsed packet data.
1019
+
1020
+ Raises:
1021
+ ProtocolError: If the packet is malformed.
1022
+
1023
+ """
1024
+ if header.length != 8:
1025
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
1026
+
1027
+ flag = Data_PingFrameFlags(
1028
+ ACK=bool(header.flags['bit_0']), # bit 0
1029
+ )
1030
+ flag.__update__({
1031
+ '__value__': schema.__flags__,
1032
+ })
1033
+
1034
+ data = Data_PingFrame(
1035
+ length=header.length,
1036
+ type=header.type,
1037
+ flags=flag,
1038
+ reserved=header.stream['reserved'],
1039
+ sid=header.stream['sid'],
1040
+ data=schema.data,
1041
+ )
1042
+ return data
1043
+
1044
+ def _read_http_goaway(self, schema: 'Schema_GoawayFrame', *,
1045
+ header: 'Schema_HTTP') -> 'Data_GoawayFrame': # pylint: disable=unused-argument
1046
+ """Read HTTP/2 ``GOAWAY`` frames.
1047
+
1048
+ Structure of HTTP/2 ``GOAWAY`` frame [:rfc:`7540`]:
1049
+
1050
+ .. code-block:: text
1051
+
1052
+ +-----------------------------------------------+
1053
+ | Length (24) |
1054
+ +---------------+---------------+---------------+
1055
+ | Type (8) | Flags (8) |
1056
+ +-+-------------+---------------+-------------------------------+
1057
+ |R| Stream Identifier (31) |
1058
+ +-+-------------+---------------+-------------------------------+
1059
+ |R| Last-Stream-ID (31) |
1060
+ +-+-------------------------------------------------------------+
1061
+ | Error Code (32) |
1062
+ +---------------------------------------------------------------+
1063
+ | Additional Debug Data (*) |
1064
+ +---------------------------------------------------------------+
1065
+
1066
+ Args:
1067
+ schema: Parsed frame schema.
1068
+ header: Parsed HTTP/2 header schema.
1069
+
1070
+ Returns:
1071
+ Parsed packet data.
1072
+
1073
+ """
1074
+ data = Data_GoawayFrame(
1075
+ length=header.length,
1076
+ type=header.type,
1077
+ flags=self._read_http_flags(schema),
1078
+ reserved=header.stream['reserved'],
1079
+ sid=header.stream['sid'],
1080
+ last_reserved=schema.stream['reserved'],
1081
+ last_sid=schema.stream['sid'],
1082
+ error=schema.error,
1083
+ debug_data=schema.debug,
1084
+ )
1085
+ return data
1086
+
1087
+ def _read_http_window_update(self, schema: 'Schema_WindowUpdateFrame', *,
1088
+ header: 'Schema_HTTP') -> 'Data_WindowUpdateFrame': # pylint: disable=unused-argument
1089
+ """Read HTTP/2 ``WINDOW_UPDATE`` frames.
1090
+
1091
+ Structure of HTTP/2 ``WINDOW_UPDATE`` frame [:rfc:`7540`]:
1092
+
1093
+ .. code-block:: text
1094
+
1095
+ +-----------------------------------------------+
1096
+ | Length (24) |
1097
+ +---------------+---------------+---------------+
1098
+ | Type (8) | Flags (8) |
1099
+ +-+-------------+---------------+-------------------------------+
1100
+ |R| Stream Identifier (31) |
1101
+ +-+-------------+---------------+-------------------------------+
1102
+ |R| Window Size Increment (31) |
1103
+ +-+-------------------------------------------------------------+
1104
+
1105
+ Args:
1106
+ schema: Parsed frame schema.
1107
+ header: Parsed HTTP/2 header schema.
1108
+
1109
+ Returns:
1110
+ Parsed packet data.
1111
+
1112
+ Raises:
1113
+ ProtocolError: If the packet is malformed.
1114
+
1115
+ """
1116
+ if header.length != 4:
1117
+ raise ProtocolError(f'HTTP/2: [Type {header.type}] invalid format')
1118
+
1119
+ data = Data_WindowUpdateFrame(
1120
+ length=header.length,
1121
+ type=header.type,
1122
+ flags=self._read_http_flags(schema),
1123
+ reserved=header.stream['reserved'],
1124
+ sid=header.stream['sid'],
1125
+ increment_reserved=schema.size['reserved'],
1126
+ increment=schema.size['incr'],
1127
+ )
1128
+ return data
1129
+
1130
+ def _read_http_continuation(self, schema: 'Schema_ContinuationFrame', *,
1131
+ header: 'Schema_HTTP') -> 'Data_ContinuationFrame':
1132
+ """Read HTTP/2 ``CONTINUATION`` frames.
1133
+
1134
+ Structure of HTTP/2 ``CONTINUATION`` frame [:rfc:`7540`]:
1135
+
1136
+ .. code-block:: text
1137
+
1138
+ +-----------------------------------------------+
1139
+ | Length (24) |
1140
+ +---------------+---------------+---------------+
1141
+ | Type (8) | Flags (8) |
1142
+ +-+-------------+---------------+-------------------------------+
1143
+ |R| Stream Identifier (31) |
1144
+ +---------------------------------------------------------------+
1145
+ | Header Block Fragment (*) ...
1146
+ +---------------------------------------------------------------+
1147
+
1148
+ Args:
1149
+ schema: Parsed frame schema.
1150
+ header: Parsed HTTP/2 header schema.
1151
+
1152
+ Returns:
1153
+ Parsed packet data.
1154
+
1155
+ """
1156
+ flag = Data_ContinuationFrameFlags(
1157
+ END_HEADERS=bool(header.flags['bit_2']), # bit 2
1158
+ )
1159
+ flag.__update__({
1160
+ '__value__': schema.__flags__,
1161
+ })
1162
+
1163
+ data = Data_ContinuationFrame(
1164
+ length=header.length,
1165
+ type=header.type,
1166
+ flags=flag,
1167
+ reserved=header.stream['reserved'],
1168
+ sid=header.stream['sid'],
1169
+ fragment=schema.fragment,
1170
+ )
1171
+ return data
1172
+
1173
+ def _make_http_none(self, frame: 'Optional[Data_UnassignedFrame]' = None, *,
1174
+ data: 'bytes' = b'',
1175
+ **kwargs: 'Any') -> 'tuple[Schema_UnassignedFrame, Flags]':
1176
+ """Make HTTP/2 unassigned frame type.
1177
+
1178
+ Args:
1179
+ frame: Frame data model.
1180
+ data: Unspecified frame data.
1181
+ **kwargs: Arbitrary keyword arguments.
1182
+
1183
+ Returns:
1184
+ Constructed frame schema and updated flags.
1185
+
1186
+ """
1187
+ if frame is not None:
1188
+ data = frame.data
1189
+
1190
+ return Schema_UnassignedFrame(
1191
+ data=data,
1192
+ ), cast('Flags', 0)
1193
+
1194
+ def _make_http_data(self, frame: 'Optional[Data_DataFrame]' = None, *,
1195
+ end_stream: 'bool' = False,
1196
+ padded: 'bool' = False,
1197
+ pad_len: 'int' = 0,
1198
+ data: 'bytes' = b'',
1199
+ padding: 'bytes' = b'',
1200
+ **kwargs: 'Any') -> 'tuple[Schema_DataFrame, Flags]':
1201
+ """Make HTTP/2 ``DATA`` frame.
1202
+
1203
+ Args:
1204
+ frame: Frame data model.
1205
+ end_stream: End of stream flag.
1206
+ padded: Padded flag, implied by a non-zero ``pad_len``.
1207
+ pad_len: Padding length.
1208
+ data: Frame data.
1209
+ padding: Padding octets, truncated or zero-filled to ``pad_len``
1210
+ octets.
1211
+ **kwargs: Arbitrary keyword arguments.
1212
+
1213
+ Returns:
1214
+ Constructed frame schema and updated flags.
1215
+
1216
+ """
1217
+ if frame is not None:
1218
+ end_stream = frame.flags.END_STREAM
1219
+ padded = frame.flags.PADDED
1220
+
1221
+ pad_len = frame.pad_len
1222
+ data = frame.data
1223
+ padding = getattr(frame, 'padding', b'')
1224
+
1225
+ flags = Schema_DataFrame.Flags(0)
1226
+ if end_stream:
1227
+ flags |= Schema_DataFrame.Flags.END_STREAM
1228
+ if padded or pad_len:
1229
+ flags |= Schema_DataFrame.Flags.PADDED
1230
+
1231
+ return Schema_DataFrame(
1232
+ pad_len=pad_len,
1233
+ data=data,
1234
+ padding=padding,
1235
+ ), flags
1236
+
1237
+ def _make_http_headers(self, frame: 'Optional[Data_HeadersFrame]' = None, *,
1238
+ end_stream: 'bool' = False,
1239
+ end_headers: 'bool' = False,
1240
+ padded: 'bool' = False,
1241
+ pad_len: 'int' = 0,
1242
+ excl_dep: 'bool' = False,
1243
+ sid_dep: 'Optional[int]' = None,
1244
+ weight: 'int' = 0,
1245
+ fragment: 'bytes' = b'',
1246
+ padding: 'bytes' = b'',
1247
+ **kwargs: 'Any') -> 'tuple[Schema_HeadersFrame, Flags]':
1248
+ """Make HTTP/2 ``HEADERS`` frame.
1249
+
1250
+ Args:
1251
+ frame: Frame data model.
1252
+ end_stream: End of stream flag.
1253
+ end_headers: End of headers flag.
1254
+ padded: Padded flag, implied by a non-zero ``pad_len``.
1255
+ pad_len: Padding length.
1256
+ excl_dep: Exclusive dependency flag.
1257
+ sid_dep: Dependency stream identifier. Giving one sets the
1258
+ ``PRIORITY`` flag.
1259
+ weight: Priority weight value.
1260
+ fragment: Header block fragment.
1261
+ padding: Padding octets, truncated or zero-filled to ``pad_len``
1262
+ octets.
1263
+ **kwargs: Arbitrary keyword arguments.
1264
+
1265
+ Returns:
1266
+ Constructed frame schema and updated flags.
1267
+
1268
+ """
1269
+ if frame is not None:
1270
+ priority = frame.flags.PRIORITY
1271
+ end_headers = frame.flags.END_HEADERS
1272
+ end_stream = frame.flags.END_STREAM
1273
+ padded = frame.flags.PADDED
1274
+
1275
+ pad_len = frame.pad_len
1276
+ excl_dep = frame.excl_dependency
1277
+ sid_dep = frame.stream_dependency
1278
+ weight = frame.weight
1279
+ fragment = frame.fragment
1280
+ padding = getattr(frame, 'padding', b'')
1281
+ else:
1282
+ priority = sid_dep is not None
1283
+ sid_dep = sid_dep or 0
1284
+
1285
+ flags = Schema_HeadersFrame.Flags(0)
1286
+ if end_stream:
1287
+ flags |= Schema_HeadersFrame.Flags.END_STREAM
1288
+ if end_headers:
1289
+ flags |= Schema_HeadersFrame.Flags.END_HEADERS
1290
+ if padded or pad_len:
1291
+ flags |= Schema_HeadersFrame.Flags.PADDED
1292
+ if priority:
1293
+ flags |= Schema_HeadersFrame.Flags.PRIORITY
1294
+
1295
+ return Schema_HeadersFrame(
1296
+ pad_len=pad_len,
1297
+ stream_dep={
1298
+ 'exclusive': excl_dep,
1299
+ 'sid': sid_dep,
1300
+ },
1301
+ weight=weight - 1 if weight else 0,
1302
+ fragment=fragment,
1303
+ padding=padding,
1304
+ ), flags
1305
+
1306
+ def _make_http_priority(self, frame: 'Optional[Data_PriorityFrame]' = None, *,
1307
+ sid_dep: 'int' = 0,
1308
+ excl_dep: 'bool' = False,
1309
+ weight: 'int' = 0,
1310
+ **kwargs: 'Any') -> 'tuple[Schema_PriorityFrame, Flags]':
1311
+ """Make HTTP/2 ``PRIORITY`` frame.
1312
+
1313
+ Args:
1314
+ frame: Frame data model.
1315
+ excl_dep: Exclusive dependency flag.
1316
+ sid_dep: Dependency stream identifier.
1317
+ weight: Priority weight value.
1318
+ **kwargs: Arbitrary keyword arguments.
1319
+
1320
+ Returns:
1321
+ Constructed frame schema and updated flags.
1322
+
1323
+ """
1324
+ if frame is not None:
1325
+ excl_dep = frame.excl_dependency
1326
+ sid_dep = frame.stream_dependency
1327
+ weight = frame.weight
1328
+
1329
+ return Schema_PriorityFrame(
1330
+ stream={
1331
+ 'exclusive': excl_dep,
1332
+ 'sid': sid_dep,
1333
+ },
1334
+ weight=weight - 1 if weight else 0,
1335
+ ), cast('Flags', 0)
1336
+
1337
+ def _make_http_rst_stream(self, frame: 'Optional[Data_RSTStreamFrame]' = None, *,
1338
+ error: 'Enum_ErrorCode | int' = Enum_ErrorCode.NO_ERROR,
1339
+ **kwargs: 'Any') -> 'tuple[Schema_RSTStreamFrame, Flags]':
1340
+ """Make HTTP/2 ``RST_STREAM`` frame.
1341
+
1342
+ Args:
1343
+ frame: Frame data model.
1344
+ error: Error code, ``NO_ERROR`` unless given.
1345
+ **kwargs: Arbitrary keyword arguments.
1346
+
1347
+ Returns:
1348
+ Constructed frame schema and updated flags.
1349
+
1350
+ Raises:
1351
+ ProtocolError: If ``error`` is a name, a :obj:`bool`, or a member
1352
+ or code the 32-bit Error Code field cannot carry.
1353
+
1354
+ .. versionchanged:: 1.5.0
1355
+
1356
+ ``error`` defaults to ``NO_ERROR``, the code :rfc:`9113#section-7`
1357
+ gives a condition that is not the result of an error, rather than
1358
+ ``HTTP_1_1_REQUIRED``, which asks the peer to use HTTP/1.1 instead
1359
+ (:issue:`2311`).
1360
+
1361
+ """
1362
+ if frame is not None:
1363
+ error_val = frame.error
1364
+ else:
1365
+ error_val = self._make_index(error, Enum_ErrorCode, bits=32, name='error code')
1366
+
1367
+ return Schema_RSTStreamFrame(
1368
+ error=error_val,
1369
+ ), cast('Flags', 0)
1370
+
1371
+ def _make_http_settings(self, frame: 'Optional[Data_SettingsFrame]' = None, *,
1372
+ ack: 'bool' = False,
1373
+ settings: 'Optional[OrderedMultiDict[Enum_Setting | int, int] | dict[Enum_Setting | int, int] | bytes | list[Schema_SettingPair | tuple[Enum_Setting | int, int]]]' = None, # pylint: disable=line-too-long
1374
+ **kwargs: 'Any') -> 'tuple[Schema_SettingsFrame, Flags]':
1375
+ """Make HTTP/2 ``SETTINGS`` frame.
1376
+
1377
+ Args:
1378
+ frame: Frame data model.
1379
+ ack: Acknowledge flag.
1380
+ settings: Settings, as raw octets, an
1381
+ :class:`~pcapkit.corekit.multidict.OrderedMultiDict`, a plain
1382
+ :obj:`dict` of identifier to value or a list of
1383
+ ``(identifier, value)`` pairs. :data:`None`, the default,
1384
+ carries no parameters at all.
1385
+ **kwargs: Arbitrary keyword arguments.
1386
+
1387
+ Returns:
1388
+ Constructed frame schema and updated flags.
1389
+
1390
+ Raises:
1391
+ ProtocolError: If ``settings`` is not :obj:`bytes`, a :obj:`dict`,
1392
+ a :obj:`list` or :data:`None`, or if an identifier other than
1393
+ a :class:`~pcapkit.protocols.application.httpv2.schema.SettingPair`'s
1394
+ is a name, a :obj:`bool`, or a member or code the 16-bit
1395
+ Identifier field cannot carry.
1396
+
1397
+ .. versionchanged:: 1.5.0
1398
+
1399
+ ``settings`` of :data:`None`, the default, builds a ``SETTINGS``
1400
+ frame with no parameters, which :rfc:`9113#section-6.5` permits,
1401
+ rather than being rejected (:issue:`2274`).
1402
+
1403
+ .. versionchanged:: 1.6.0
1404
+
1405
+ A ``frame`` the capture cut inside its settings, as its
1406
+ ``__short_read__`` records, packs the settings its parse read from the
1407
+ octets its ``packet`` holds with zeros after them to the Length it
1408
+ declares, since that parse reads no setting past the data, so its
1409
+ rebuild declares that Length too; with its settings edited, the Length
1410
+ is computed as for a whole frame (:issue:`2756`).
1411
+
1412
+ """
1413
+ if frame is not None:
1414
+ ack = frame.flags.ACK
1415
+ settings = frame.settings
1416
+
1417
+ flags = Schema_SettingsFrame.Flags(0)
1418
+ if ack:
1419
+ flags |= Schema_SettingsFrame.Flags.ACK
1420
+
1421
+ if settings is None:
1422
+ # A SETTINGS frame carrying no parameters is valid (RFC 9113
1423
+ # §6.5), so the default builds one rather than being rejected
1424
+ # (#2274).
1425
+ settings_val = [] # type: bytes | list[Schema_SettingPair]
1426
+ elif isinstance(settings, bytes):
1427
+ settings_val = settings
1428
+ elif isinstance(settings, dict):
1429
+ settings_val = []
1430
+ # A plain ``dict`` has no ``multi`` keyword (#2223).
1431
+ items = settings.items(multi=True) if isinstance(settings, MultiDict) else settings.items()
1432
+ for key, val in items:
1433
+ settings_val.append(Schema_SettingPair(
1434
+ id=self._make_index(key, Enum_Setting, bits=16, name='setting identifier'),
1435
+ value=val,
1436
+ ))
1437
+ elif isinstance(settings, list):
1438
+ settings_val = []
1439
+ for item in settings:
1440
+ if isinstance(item, Schema_SettingPair):
1441
+ temp = item
1442
+ else:
1443
+ id, value = item
1444
+ temp = Schema_SettingPair(
1445
+ id=self._make_index(id, Enum_Setting, bits=16, name='setting identifier'),
1446
+ value=value,
1447
+ )
1448
+ settings_val.append(temp)
1449
+ else:
1450
+ raise ProtocolError(f'HTTP/2: [Type {Enum_Frame.SETTINGS}] invalid settings: '
1451
+ f'{settings!r}')
1452
+
1453
+ # NOTE: An unedited cut frame packs the octets its ``packet`` captured, zero to the pair, and
1454
+ # keeps its Length in the zeros past them (#2756); a dict rebuilds as the base data model.
1455
+ record = frame.get('__short_read__') if isinstance(frame, Data_HTTP) else None
1456
+ if frame is not None and record is not None and isinstance(settings_val, list):
1457
+ packed = b''.join(pair.pack() for pair in settings_val)
1458
+ # A cut in the frame header leaves no setting captured.
1459
+ read = cast('bytes', frame.get('packet', b''))[:record[1]] if record[0] == 'frame' else b''
1460
+ if packed == read + bytes(-len(read) % 6) and len(packed) < frame.length:
1461
+ settings_val = packed + bytes(frame.length - len(packed))
1462
+
1463
+ return Schema_SettingsFrame(
1464
+ settings=settings_val,
1465
+ ), flags
1466
+
1467
+ def _make_http_push_promise(self, frame: 'Optional[Data_PushPromiseFrame]' = None, *,
1468
+ end_headers: 'bool' = False,
1469
+ padded: 'bool' = False,
1470
+ pad_len: 'int' = 0,
1471
+ promised_reserved: 'int' = 0,
1472
+ promised_sid: 'int' = 0,
1473
+ fragment: 'bytes' = b'',
1474
+ padding: 'bytes' = b'',
1475
+ **kwargs: 'Any') -> 'tuple[Schema_PushPromiseFrame, Flags]':
1476
+ """Make HTTP/2 ``PUSH_PROMISE`` frame.
1477
+
1478
+ Args:
1479
+ frame: Frame data model.
1480
+ end_headers: End of headers flag.
1481
+ padded: Padded flag, implied by a non-zero ``pad_len``.
1482
+ pad_len: Padding length.
1483
+ promised_reserved: Reserved bit of the promised stream identifier.
1484
+ promised_sid: Promised stream identifier.
1485
+ fragment: Header block fragment.
1486
+ padding: Padding octets, truncated or zero-filled to ``pad_len``
1487
+ octets.
1488
+ **kwargs: Arbitrary keyword arguments.
1489
+
1490
+ Returns:
1491
+ Constructed frame schema and updated flags.
1492
+
1493
+ """
1494
+ if frame is not None:
1495
+ end_headers = frame.flags.END_HEADERS
1496
+ padded = frame.flags.PADDED
1497
+ pad_len = frame.pad_len
1498
+ promised_reserved = frame.promised_reserved
1499
+ promised_sid = frame.promised_sid
1500
+ fragment = frame.fragment
1501
+ padding = getattr(frame, 'padding', b'')
1502
+
1503
+ flags = Schema_PushPromiseFrame.Flags(0)
1504
+ if end_headers:
1505
+ flags |= Schema_PushPromiseFrame.Flags.END_HEADERS
1506
+ if padded or pad_len:
1507
+ flags |= Schema_PushPromiseFrame.Flags.PADDED
1508
+
1509
+ return Schema_PushPromiseFrame(
1510
+ pad_len=pad_len,
1511
+ stream={
1512
+ 'reserved': promised_reserved,
1513
+ 'sid': promised_sid,
1514
+ },
1515
+ fragment=fragment,
1516
+ padding=padding,
1517
+ ), flags
1518
+
1519
+ def _make_http_ping(self, frame: 'Optional[Data_PingFrame]' = None, *,
1520
+ ack: 'bool' = False,
1521
+ opaque_data: 'bytes' = bytes(8),
1522
+ **kwargs: 'Any') -> 'tuple[Schema_PingFrame, Flags]':
1523
+ """Make HTTP/2 ``PING`` frame.
1524
+
1525
+ Args:
1526
+ frame: Frame data model.
1527
+ ack: Acknowledge flag.
1528
+ opaque_data: Opaque data, exactly 8 octets.
1529
+ **kwargs: Arbitrary keyword arguments.
1530
+
1531
+ Returns:
1532
+ Constructed frame schema and updated flags.
1533
+
1534
+ Raises:
1535
+ ProtocolError: If ``opaque_data`` is not 8 octets long.
1536
+
1537
+ """
1538
+ if frame is not None:
1539
+ ack = frame.flags.ACK
1540
+ opaque_data = frame.data
1541
+ if len(opaque_data) != 8:
1542
+ raise ProtocolError(f'HTTP/2: [Type {Enum_Frame.PING}] opaque data must be 8 octets, '
1543
+ f'not {len(opaque_data)}')
1544
+
1545
+ flags = Schema_PingFrame.Flags(0)
1546
+ if ack:
1547
+ flags |= Schema_PingFrame.Flags.ACK
1548
+
1549
+ return Schema_PingFrame(
1550
+ data=opaque_data,
1551
+ ), flags
1552
+
1553
+ def _make_http_goaway(self, frame: 'Optional[Data_GoawayFrame]' = None, *,
1554
+ last_reserved: 'int' = 0,
1555
+ last_sid: 'int' = 0,
1556
+ error: 'Enum_ErrorCode | int' = Enum_ErrorCode.NO_ERROR,
1557
+ debug_data: 'bytes' = b'',
1558
+ **kwargs: 'Any') -> 'tuple[Schema_GoawayFrame, Flags]':
1559
+ """Make HTTP/2 ``GOAWAY`` frame.
1560
+
1561
+ Args:
1562
+ frame: Frame data model.
1563
+ last_reserved: Reserved bit of the last stream identifier.
1564
+ last_sid: Last stream identifier.
1565
+ error: Error code, ``NO_ERROR`` unless given.
1566
+ debug_data: Additional debug data.
1567
+ **kwargs: Arbitrary keyword arguments.
1568
+
1569
+ Returns:
1570
+ Constructed frame schema and updated flags.
1571
+
1572
+ Raises:
1573
+ ProtocolError: If ``error`` is a name, a :obj:`bool`, or a member
1574
+ or code the 32-bit Error Code field cannot carry.
1575
+
1576
+ .. versionchanged:: 1.5.0
1577
+
1578
+ ``error`` defaults to ``NO_ERROR``, the code :rfc:`9113#section-7`
1579
+ gives a condition that is not the result of an error, rather than
1580
+ ``HTTP_1_1_REQUIRED``, which asks the peer to use HTTP/1.1 instead
1581
+ (:issue:`2311`).
1582
+
1583
+ """
1584
+ if frame is not None:
1585
+ last_reserved = frame.last_reserved
1586
+ last_sid = frame.last_sid
1587
+ error_val = frame.error
1588
+ debug = frame.debug_data
1589
+ else:
1590
+ error_val = self._make_index(error, Enum_ErrorCode, bits=32, name='error code')
1591
+ debug = debug_data
1592
+
1593
+ return Schema_GoawayFrame(
1594
+ stream={
1595
+ 'reserved': last_reserved,
1596
+ 'sid': last_sid,
1597
+ },
1598
+ error=error_val,
1599
+ debug=debug,
1600
+ ), cast('Flags', 0)
1601
+
1602
+ def _make_http_window_update(self, frame: 'Optional[Data_WindowUpdateFrame]' = None, *,
1603
+ incr_reserved: 'int' = 0,
1604
+ incr: 'int' = 0,
1605
+ **kwargs: 'Any') -> 'tuple[Schema_WindowUpdateFrame, Flags]':
1606
+ """Make HTTP/2 ``WINDOW_UPDATE`` frame.
1607
+
1608
+ Args:
1609
+ frame: Frame data model.
1610
+ incr_reserved: Reserved bit of the window size increment.
1611
+ incr: Window size increment.
1612
+ **kwargs: Arbitrary keyword arguments.
1613
+
1614
+ Returns:
1615
+ Constructed frame schema and updated flags.
1616
+
1617
+ """
1618
+ if frame is not None:
1619
+ incr_reserved = frame.increment_reserved
1620
+ incr = frame.increment
1621
+
1622
+ return Schema_WindowUpdateFrame(
1623
+ size={
1624
+ 'reserved': incr_reserved,
1625
+ 'incr': incr,
1626
+ }
1627
+ ), cast('Flags', 0)
1628
+
1629
+ def _make_http_continuation(self, frame: 'Optional[Data_ContinuationFrame]' = None, *,
1630
+ end_headers: 'bool' = False,
1631
+ fragment: 'bytes' = b'',
1632
+ **kwargs: 'Any') -> 'tuple[Schema_ContinuationFrame, Flags]':
1633
+ """Make HTTP/2 ``CONTINUATION`` frame.
1634
+
1635
+ Args:
1636
+ frame: Frame data model.
1637
+ end_headers: End of headers flag.
1638
+ fragment: Header block fragment.
1639
+ **kwargs: Arbitrary keyword arguments.
1640
+
1641
+ Returns:
1642
+ Constructed frame schema and updated flags.
1643
+
1644
+ """
1645
+ if frame is not None:
1646
+ end_headers = frame.flags.END_HEADERS
1647
+ fragment = frame.fragment
1648
+
1649
+ flags = Schema_ContinuationFrame.Flags(0)
1650
+ if end_headers:
1651
+ flags |= Schema_ContinuationFrame.Flags.END_HEADERS
1652
+
1653
+ return Schema_ContinuationFrame(
1654
+ fragment=fragment,
1655
+ ), flags
1656
+
1657
+ @staticmethod
1658
+ def _read_http_flags(schema: 'Schema_FrameType') -> 'Data_Flags':
1659
+ """Read the flags of an HTTP/2 frame type that defines none.
1660
+
1661
+ Args:
1662
+ schema: Parsed frame schema.
1663
+
1664
+ Returns:
1665
+ Flags with the raw flags octet as ``__value__``.
1666
+
1667
+ """
1668
+ flags = Data_Flags()
1669
+ flags.__update__({
1670
+ '__value__': schema.__flags__,
1671
+ })
1672
+ return flags
1673
+
1674
+ def _import_next_layer(self, proto: 'int', length: 'Optional[int]' = None, *, # type: ignore[override]
1675
+ packet: 'Optional[dict[str, Any]]' = None) -> 'ProtocolBase':
1676
+ """Import next layer extractor: a further whole frame, or the rest undissected.
1677
+
1678
+ A TCP segment may carry several frames (:issue:`2536`). So the ``-1``
1679
+ remainder is dissected as this class when :func:`_opens_whole_frame`
1680
+ finds a whole frame opening it, and is otherwise kept as
1681
+ :class:`~pcapkit.protocols.misc.raw.protocol.Raw`, as
1682
+ :meth:`Application._import_next_layer
1683
+ <pcapkit.protocols.application.application.Application._import_next_layer>`
1684
+ keeps it. A frame the segment ends inside is the reassembly limit, and
1685
+ stays raw.
1686
+
1687
+ Arguments:
1688
+ proto: next layer protocol index; only the ``-1`` sentinel
1689
+ (the rest of the segment) is accepted
1690
+ length: valid (*non-padding*) length
1691
+ packet: packet info (passed from :meth:`self.unpack <pcapkit.protocols.protocol.Protocol.unpack>`)
1692
+
1693
+ Returns:
1694
+ Instance of this class for a further frame, or as
1695
+ :meth:`Application._import_next_layer
1696
+ <pcapkit.protocols.application.application.Application._import_next_layer>`
1697
+ returns otherwise.
1698
+
1699
+ """
1700
+ if proto == -1 and _opens_whole_frame(self._get_payload()[:length]) and not self._sigterm:
1701
+ return self._import_next_frame(proto, length, packet=packet) # type: ignore[misc,call-arg]
1702
+ return super()._import_next_layer(proto, length, packet=packet)
1703
+
1704
+ @beholder # type: ignore[arg-type]
1705
+ def _import_next_frame(self, proto: 'int', length: 'Optional[int]' = None, *, # type: ignore[misc]
1706
+ packet: 'Optional[dict[str, Any]]' = None) -> 'ProtocolBase':
1707
+ """Import the further frame :meth:`_import_next_layer` found.
1708
+
1709
+ Arguments:
1710
+ proto: next layer protocol index, the ``-1`` sentinel
1711
+ length: valid (*non-padding*) length
1712
+ packet: packet info (passed from :meth:`self.unpack <pcapkit.protocols.protocol.Protocol.unpack>`)
1713
+
1714
+ Returns:
1715
+ Instance of this class, or of :class:`~pcapkit.protocols.misc.raw.protocol.Raw`
1716
+ carrying the parser's ``error`` when
1717
+ :func:`~pcapkit.corekit.decorators.beholder` replaces a frame that
1718
+ fails to parse.
1719
+
1720
+ """
1721
+ file_ = self._get_payload()
1722
+ return self._parse_next_layer(type(self), file_, len(file_) if length is None else length,
1723
+ alias=proto, packet=packet, layer=self._exlayer,
1724
+ protocol=self._exproto, __context__=self._exctx)