pypcapkit 1.3.5.post6__pp310-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (466) hide show
  1. pcapkit/__init__.py +124 -0
  2. pcapkit/__main__.py +138 -0
  3. pcapkit/all.py +136 -0
  4. pcapkit/const/__init__.py +81 -0
  5. pcapkit/const/arp/__init__.py +25 -0
  6. pcapkit/const/arp/hardware.py +181 -0
  7. pcapkit/const/arp/operation.py +131 -0
  8. pcapkit/const/ftp/__init__.py +25 -0
  9. pcapkit/const/ftp/command.py +309 -0
  10. pcapkit/const/ftp/return_code.py +304 -0
  11. pcapkit/const/hip/__init__.py +94 -0
  12. pcapkit/const/hip/certificate.py +77 -0
  13. pcapkit/const/hip/cipher.py +65 -0
  14. pcapkit/const/hip/di.py +59 -0
  15. pcapkit/const/hip/ecdsa_curve.py +59 -0
  16. pcapkit/const/hip/ecdsa_low_curve.py +56 -0
  17. pcapkit/const/hip/eddsa_curve.py +65 -0
  18. pcapkit/const/hip/esp_transform_suite.py +98 -0
  19. pcapkit/const/hip/group.py +86 -0
  20. pcapkit/const/hip/hi_algorithm.py +86 -0
  21. pcapkit/const/hip/hit_suite.py +68 -0
  22. pcapkit/const/hip/nat_traversal.py +62 -0
  23. pcapkit/const/hip/notify_message.py +200 -0
  24. pcapkit/const/hip/packet.py +89 -0
  25. pcapkit/const/hip/parameter.py +377 -0
  26. pcapkit/const/hip/registration.py +68 -0
  27. pcapkit/const/hip/registration_failure.py +84 -0
  28. pcapkit/const/hip/suite.py +71 -0
  29. pcapkit/const/hip/transport.py +59 -0
  30. pcapkit/const/http/__init__.py +39 -0
  31. pcapkit/const/http/error_code.py +95 -0
  32. pcapkit/const/http/frame.py +95 -0
  33. pcapkit/const/http/method.py +184 -0
  34. pcapkit/const/http/setting.py +96 -0
  35. pcapkit/const/http/status_code.py +298 -0
  36. pcapkit/const/ipv4/__init__.py +57 -0
  37. pcapkit/const/ipv4/classification_level.py +64 -0
  38. pcapkit/const/ipv4/option_class.py +55 -0
  39. pcapkit/const/ipv4/option_number.py +137 -0
  40. pcapkit/const/ipv4/protection_authority.py +63 -0
  41. pcapkit/const/ipv4/qs_function.py +51 -0
  42. pcapkit/const/ipv4/router_alert.py +251 -0
  43. pcapkit/const/ipv4/tos_del.py +51 -0
  44. pcapkit/const/ipv4/tos_ecn.py +55 -0
  45. pcapkit/const/ipv4/tos_pre.py +63 -0
  46. pcapkit/const/ipv4/tos_rel.py +51 -0
  47. pcapkit/const/ipv4/tos_thr.py +51 -0
  48. pcapkit/const/ipv4/ts_flag.py +53 -0
  49. pcapkit/const/ipv6/__init__.py +53 -0
  50. pcapkit/const/ipv6/extension_header.py +69 -0
  51. pcapkit/const/ipv6/option.py +137 -0
  52. pcapkit/const/ipv6/option_action.py +55 -0
  53. pcapkit/const/ipv6/qs_function.py +51 -0
  54. pcapkit/const/ipv6/router_alert.py +266 -0
  55. pcapkit/const/ipv6/routing.py +80 -0
  56. pcapkit/const/ipv6/seed_id.py +55 -0
  57. pcapkit/const/ipv6/smf_dpd_mode.py +51 -0
  58. pcapkit/const/ipv6/tagger_id.py +62 -0
  59. pcapkit/const/ipx/__init__.py +27 -0
  60. pcapkit/const/ipx/packet.py +72 -0
  61. pcapkit/const/ipx/socket.py +104 -0
  62. pcapkit/const/l2tp/__init__.py +21 -0
  63. pcapkit/const/l2tp/type.py +51 -0
  64. pcapkit/const/mh/__init__.py +204 -0
  65. pcapkit/const/mh/access_type.py +92 -0
  66. pcapkit/const/mh/ack_status_code.py +71 -0
  67. pcapkit/const/mh/ani_suboption.py +74 -0
  68. pcapkit/const/mh/auth_subtype.py +53 -0
  69. pcapkit/const/mh/binding_ack_flag.py +66 -0
  70. pcapkit/const/mh/binding_error.py +51 -0
  71. pcapkit/const/mh/binding_revocation.py +59 -0
  72. pcapkit/const/mh/binding_update_flag.py +81 -0
  73. pcapkit/const/mh/cga_extension.py +66 -0
  74. pcapkit/const/mh/cga_sec.py +57 -0
  75. pcapkit/const/mh/cga_type.py +68 -0
  76. pcapkit/const/mh/dhcp_support_mode.py +53 -0
  77. pcapkit/const/mh/dns_status_code.py +65 -0
  78. pcapkit/const/mh/dsmip6_tls_packet.py +62 -0
  79. pcapkit/const/mh/dsmipv6_home_address.py +74 -0
  80. pcapkit/const/mh/enumerating_algorithm.py +56 -0
  81. pcapkit/const/mh/fb_ack_status.py +62 -0
  82. pcapkit/const/mh/fb_action.py +71 -0
  83. pcapkit/const/mh/fb_indication_trigger.py +65 -0
  84. pcapkit/const/mh/fb_type.py +59 -0
  85. pcapkit/const/mh/flow_id_status.py +77 -0
  86. pcapkit/const/mh/flow_id_suboption.py +71 -0
  87. pcapkit/const/mh/handoff_type.py +71 -0
  88. pcapkit/const/mh/handover_ack_flag.py +54 -0
  89. pcapkit/const/mh/handover_ack_status.py +92 -0
  90. pcapkit/const/mh/handover_initiate_flag.py +57 -0
  91. pcapkit/const/mh/handover_initiate_status.py +62 -0
  92. pcapkit/const/mh/home_address_reply.py +71 -0
  93. pcapkit/const/mh/lla_code.py +63 -0
  94. pcapkit/const/mh/lma_mag_suboption.py +59 -0
  95. pcapkit/const/mh/mn_group_id.py +59 -0
  96. pcapkit/const/mh/mn_id_subtype.py +77 -0
  97. pcapkit/const/mh/operator_id.py +63 -0
  98. pcapkit/const/mh/option.py +260 -0
  99. pcapkit/const/mh/packet.py +119 -0
  100. pcapkit/const/mh/qos_attribute.py +89 -0
  101. pcapkit/const/mh/revocation_status_code.py +83 -0
  102. pcapkit/const/mh/revocation_trigger.py +86 -0
  103. pcapkit/const/mh/status_code.py +232 -0
  104. pcapkit/const/mh/traffic_selector.py +62 -0
  105. pcapkit/const/mh/upa_status.py +71 -0
  106. pcapkit/const/mh/upn_reason.py +80 -0
  107. pcapkit/const/ospf/__init__.py +27 -0
  108. pcapkit/const/ospf/authentication.py +65 -0
  109. pcapkit/const/ospf/packet.py +71 -0
  110. pcapkit/const/pcapng/__init__.py +51 -0
  111. pcapkit/const/pcapng/block_type.py +152 -0
  112. pcapkit/const/pcapng/filter_type.py +48 -0
  113. pcapkit/const/pcapng/hash_algorithm.py +59 -0
  114. pcapkit/const/pcapng/option_type.py +233 -0
  115. pcapkit/const/pcapng/record_type.py +57 -0
  116. pcapkit/const/pcapng/secrets_type.py +56 -0
  117. pcapkit/const/pcapng/verdict_type.py +53 -0
  118. pcapkit/const/reg/__init__.py +34 -0
  119. pcapkit/const/reg/apptype.py +32728 -0
  120. pcapkit/const/reg/ethertype.py +714 -0
  121. pcapkit/const/reg/linktype.py +890 -0
  122. pcapkit/const/reg/transtype.py +526 -0
  123. pcapkit/const/tcp/__init__.py +35 -0
  124. pcapkit/const/tcp/checksum.py +55 -0
  125. pcapkit/const/tcp/flags.py +73 -0
  126. pcapkit/const/tcp/mp_tcp_option.py +80 -0
  127. pcapkit/const/tcp/option.py +198 -0
  128. pcapkit/const/vlan/__init__.py +23 -0
  129. pcapkit/const/vlan/priority_level.py +71 -0
  130. pcapkit/corekit/__init__.py +59 -0
  131. pcapkit/corekit/fields/__init__.py +45 -0
  132. pcapkit/corekit/fields/collections.py +282 -0
  133. pcapkit/corekit/fields/field.py +269 -0
  134. pcapkit/corekit/fields/ipaddress.py +274 -0
  135. pcapkit/corekit/fields/misc.py +722 -0
  136. pcapkit/corekit/fields/numbers.py +375 -0
  137. pcapkit/corekit/fields/strings.py +245 -0
  138. pcapkit/corekit/infoclass.py +394 -0
  139. pcapkit/corekit/io.py +506 -0
  140. pcapkit/corekit/module.py +39 -0
  141. pcapkit/corekit/multidict.py +626 -0
  142. pcapkit/corekit/protochain.py +263 -0
  143. pcapkit/corekit/version.py +33 -0
  144. pcapkit/dumpkit/__init__.py +15 -0
  145. pcapkit/dumpkit/common.py +199 -0
  146. pcapkit/dumpkit/null.py +77 -0
  147. pcapkit/dumpkit/pcap.py +144 -0
  148. pcapkit/foundation/__init__.py +45 -0
  149. pcapkit/foundation/engines/__init__.py +36 -0
  150. pcapkit/foundation/engines/dpkt.py +230 -0
  151. pcapkit/foundation/engines/engine.py +194 -0
  152. pcapkit/foundation/engines/pcap.py +188 -0
  153. pcapkit/foundation/engines/pcapng.py +310 -0
  154. pcapkit/foundation/engines/pyshark.py +166 -0
  155. pcapkit/foundation/engines/scapy.py +161 -0
  156. pcapkit/foundation/extraction.py +915 -0
  157. pcapkit/foundation/reassembly/__init__.py +49 -0
  158. pcapkit/foundation/reassembly/data/__init__.py +48 -0
  159. pcapkit/foundation/reassembly/data/ip.py +117 -0
  160. pcapkit/foundation/reassembly/data/tcp.py +145 -0
  161. pcapkit/foundation/reassembly/ip.py +192 -0
  162. pcapkit/foundation/reassembly/ipv4.py +50 -0
  163. pcapkit/foundation/reassembly/ipv6.py +50 -0
  164. pcapkit/foundation/reassembly/reassembly.py +389 -0
  165. pcapkit/foundation/reassembly/tcp.py +249 -0
  166. pcapkit/foundation/registry/__init__.py +41 -0
  167. pcapkit/foundation/registry/foundation.py +327 -0
  168. pcapkit/foundation/registry/protocols.py +885 -0
  169. pcapkit/foundation/traceflow/__init__.py +44 -0
  170. pcapkit/foundation/traceflow/data/__init__.py +30 -0
  171. pcapkit/foundation/traceflow/data/tcp.py +105 -0
  172. pcapkit/foundation/traceflow/tcp.py +159 -0
  173. pcapkit/foundation/traceflow/traceflow.py +390 -0
  174. pcapkit/interface/__init__.py +22 -0
  175. pcapkit/interface/core.py +185 -0
  176. pcapkit/interface/misc.py +120 -0
  177. pcapkit/protocols/__init__.py +85 -0
  178. pcapkit/protocols/application/NotImplemented/bgp.py +0 -0
  179. pcapkit/protocols/application/NotImplemented/dhcp.py +0 -0
  180. pcapkit/protocols/application/NotImplemented/dhcpv6.py +0 -0
  181. pcapkit/protocols/application/NotImplemented/dns.py +0 -0
  182. pcapkit/protocols/application/NotImplemented/imap.py +0 -0
  183. pcapkit/protocols/application/NotImplemented/ldap.py +0 -0
  184. pcapkit/protocols/application/NotImplemented/mqtt.py +0 -0
  185. pcapkit/protocols/application/NotImplemented/nntp.py +0 -0
  186. pcapkit/protocols/application/NotImplemented/ntp.py +0 -0
  187. pcapkit/protocols/application/NotImplemented/onc_rpc.py +0 -0
  188. pcapkit/protocols/application/NotImplemented/pop.py +0 -0
  189. pcapkit/protocols/application/NotImplemented/rip.py +0 -0
  190. pcapkit/protocols/application/NotImplemented/rtp.py +0 -0
  191. pcapkit/protocols/application/NotImplemented/sip.py +0 -0
  192. pcapkit/protocols/application/NotImplemented/smtp.py +0 -0
  193. pcapkit/protocols/application/NotImplemented/snmp.py +0 -0
  194. pcapkit/protocols/application/NotImplemented/ssh.py +0 -0
  195. pcapkit/protocols/application/NotImplemented/telnet.py +0 -0
  196. pcapkit/protocols/application/NotImplemented/tls.py +0 -0
  197. pcapkit/protocols/application/NotImplemented/xmpp.py +0 -0
  198. pcapkit/protocols/application/__init__.py +34 -0
  199. pcapkit/protocols/application/application.py +114 -0
  200. pcapkit/protocols/application/ftp.py +206 -0
  201. pcapkit/protocols/application/http.py +176 -0
  202. pcapkit/protocols/application/httpv1.py +320 -0
  203. pcapkit/protocols/application/httpv2.py +1255 -0
  204. pcapkit/protocols/data/__init__.py +192 -0
  205. pcapkit/protocols/data/application/__init__.py +57 -0
  206. pcapkit/protocols/data/application/ftp.py +59 -0
  207. pcapkit/protocols/data/application/httpv1.py +79 -0
  208. pcapkit/protocols/data/application/httpv2.py +293 -0
  209. pcapkit/protocols/data/data.py +25 -0
  210. pcapkit/protocols/data/internet/__init__.py +298 -0
  211. pcapkit/protocols/data/internet/ah.py +31 -0
  212. pcapkit/protocols/data/internet/hip.py +804 -0
  213. pcapkit/protocols/data/internet/hopopt.py +351 -0
  214. pcapkit/protocols/data/internet/ipv4.py +369 -0
  215. pcapkit/protocols/data/internet/ipv6.py +67 -0
  216. pcapkit/protocols/data/internet/ipv6_frag.py +29 -0
  217. pcapkit/protocols/data/internet/ipv6_opts.py +368 -0
  218. pcapkit/protocols/data/internet/ipv6_route.py +86 -0
  219. pcapkit/protocols/data/internet/ipx.py +56 -0
  220. pcapkit/protocols/data/internet/mh.py +509 -0
  221. pcapkit/protocols/data/link/__init__.py +33 -0
  222. pcapkit/protocols/data/link/arp.py +74 -0
  223. pcapkit/protocols/data/link/ethernet.py +28 -0
  224. pcapkit/protocols/data/link/l2tp.py +63 -0
  225. pcapkit/protocols/data/link/ospf.py +58 -0
  226. pcapkit/protocols/data/link/vlan.py +42 -0
  227. pcapkit/protocols/data/misc/__init__.py +109 -0
  228. pcapkit/protocols/data/misc/null.py +18 -0
  229. pcapkit/protocols/data/misc/pcap/__init__.py +18 -0
  230. pcapkit/protocols/data/misc/pcap/frame.py +56 -0
  231. pcapkit/protocols/data/misc/pcap/header.py +53 -0
  232. pcapkit/protocols/data/misc/pcapng.py +925 -0
  233. pcapkit/protocols/data/misc/raw.py +25 -0
  234. pcapkit/protocols/data/protocol.py +32 -0
  235. pcapkit/protocols/data/transport/__init__.py +71 -0
  236. pcapkit/protocols/data/transport/tcp.py +555 -0
  237. pcapkit/protocols/data/transport/udp.py +29 -0
  238. pcapkit/protocols/internet/NotImplemented/ecn.py +0 -0
  239. pcapkit/protocols/internet/NotImplemented/esp.py +97 -0
  240. pcapkit/protocols/internet/NotImplemented/icmp.py +0 -0
  241. pcapkit/protocols/internet/NotImplemented/icmpv6.py +0 -0
  242. pcapkit/protocols/internet/NotImplemented/igmp.py +0 -0
  243. pcapkit/protocols/internet/NotImplemented/shim6.py +0 -0
  244. pcapkit/protocols/internet/__init__.py +43 -0
  245. pcapkit/protocols/internet/ah.py +275 -0
  246. pcapkit/protocols/internet/hip.py +4727 -0
  247. pcapkit/protocols/internet/hopopt.py +1879 -0
  248. pcapkit/protocols/internet/internet.py +249 -0
  249. pcapkit/protocols/internet/ip.py +51 -0
  250. pcapkit/protocols/internet/ipsec.py +50 -0
  251. pcapkit/protocols/internet/ipv4.py +1782 -0
  252. pcapkit/protocols/internet/ipv6.py +412 -0
  253. pcapkit/protocols/internet/ipv6_frag.py +258 -0
  254. pcapkit/protocols/internet/ipv6_opts.py +1890 -0
  255. pcapkit/protocols/internet/ipv6_route.py +708 -0
  256. pcapkit/protocols/internet/ipx.py +230 -0
  257. pcapkit/protocols/internet/mh.py +2764 -0
  258. pcapkit/protocols/link/NotImplemented/dsl.py +0 -0
  259. pcapkit/protocols/link/NotImplemented/eapol.py +1 -0
  260. pcapkit/protocols/link/NotImplemented/fddi.py +0 -0
  261. pcapkit/protocols/link/NotImplemented/isdn.py +0 -0
  262. pcapkit/protocols/link/NotImplemented/ndp.py +0 -0
  263. pcapkit/protocols/link/NotImplemented/ppp.py +0 -0
  264. pcapkit/protocols/link/__init__.py +35 -0
  265. pcapkit/protocols/link/arp.py +421 -0
  266. pcapkit/protocols/link/ethernet.py +248 -0
  267. pcapkit/protocols/link/l2tp.py +267 -0
  268. pcapkit/protocols/link/link.py +140 -0
  269. pcapkit/protocols/link/ospf.py +342 -0
  270. pcapkit/protocols/link/rarp.py +82 -0
  271. pcapkit/protocols/link/vlan.py +225 -0
  272. pcapkit/protocols/misc/__init__.py +37 -0
  273. pcapkit/protocols/misc/null.py +129 -0
  274. pcapkit/protocols/misc/pcap/__init__.py +17 -0
  275. pcapkit/protocols/misc/pcap/frame.py +478 -0
  276. pcapkit/protocols/misc/pcap/header.py +358 -0
  277. pcapkit/protocols/misc/pcapng.py +5520 -0
  278. pcapkit/protocols/misc/raw.py +180 -0
  279. pcapkit/protocols/protocol.py +1216 -0
  280. pcapkit/protocols/schema/__init__.py +140 -0
  281. pcapkit/protocols/schema/application/__init__.py +40 -0
  282. pcapkit/protocols/schema/application/ftp.py +21 -0
  283. pcapkit/protocols/schema/application/httpv1.py +21 -0
  284. pcapkit/protocols/schema/application/httpv2.py +384 -0
  285. pcapkit/protocols/schema/internet/__init__.py +294 -0
  286. pcapkit/protocols/schema/internet/ah.py +40 -0
  287. pcapkit/protocols/schema/internet/hip.py +1184 -0
  288. pcapkit/protocols/schema/internet/hopopt.py +679 -0
  289. pcapkit/protocols/schema/internet/ipv4.py +576 -0
  290. pcapkit/protocols/schema/internet/ipv6.py +63 -0
  291. pcapkit/protocols/schema/internet/ipv6_frag.py +48 -0
  292. pcapkit/protocols/schema/internet/ipv6_opts.py +680 -0
  293. pcapkit/protocols/schema/internet/ipv6_route.py +197 -0
  294. pcapkit/protocols/schema/internet/ipx.py +40 -0
  295. pcapkit/protocols/schema/internet/mh.py +718 -0
  296. pcapkit/protocols/schema/link/__init__.py +19 -0
  297. pcapkit/protocols/schema/link/arp.py +39 -0
  298. pcapkit/protocols/schema/link/ethernet.py +51 -0
  299. pcapkit/protocols/schema/link/l2tp.py +88 -0
  300. pcapkit/protocols/schema/link/ospf.py +90 -0
  301. pcapkit/protocols/schema/link/vlan.py +69 -0
  302. pcapkit/protocols/schema/misc/__init__.py +108 -0
  303. pcapkit/protocols/schema/misc/null.py +18 -0
  304. pcapkit/protocols/schema/misc/pcap/__init__.py +10 -0
  305. pcapkit/protocols/schema/misc/pcap/frame.py +51 -0
  306. pcapkit/protocols/schema/misc/pcap/header.py +63 -0
  307. pcapkit/protocols/schema/misc/pcapng.py +1689 -0
  308. pcapkit/protocols/schema/misc/raw.py +24 -0
  309. pcapkit/protocols/schema/schema.py +809 -0
  310. pcapkit/protocols/schema/transport/__init__.py +69 -0
  311. pcapkit/protocols/schema/transport/tcp.py +928 -0
  312. pcapkit/protocols/schema/transport/udp.py +90 -0
  313. pcapkit/protocols/transport/NotImplemented/dccp.py +0 -0
  314. pcapkit/protocols/transport/NotImplemented/rsvp.py +0 -0
  315. pcapkit/protocols/transport/NotImplemented/sctp.py +0 -0
  316. pcapkit/protocols/transport/__init__.py +27 -0
  317. pcapkit/protocols/transport/tcp.py +3025 -0
  318. pcapkit/protocols/transport/transport.py +158 -0
  319. pcapkit/protocols/transport/udp.py +214 -0
  320. pcapkit/py.typed +0 -0
  321. pcapkit/toolkit/__init__.py +57 -0
  322. pcapkit/toolkit/dpkt.py +306 -0
  323. pcapkit/toolkit/pcap.py +212 -0
  324. pcapkit/toolkit/pcapng.py +251 -0
  325. pcapkit/toolkit/pyshark.py +99 -0
  326. pcapkit/toolkit/scapy.py +297 -0
  327. pcapkit/utilities/__init__.py +20 -0
  328. pcapkit/utilities/compat.py +196 -0
  329. pcapkit/utilities/decorators.py +197 -0
  330. pcapkit/utilities/exceptions.py +365 -0
  331. pcapkit/utilities/logging.py +55 -0
  332. pcapkit/utilities/warnings.py +185 -0
  333. pcapkit/vendor/__init__.py +105 -0
  334. pcapkit/vendor/__main__.py +92 -0
  335. pcapkit/vendor/arp/__init__.py +27 -0
  336. pcapkit/vendor/arp/hardware.py +29 -0
  337. pcapkit/vendor/arp/operation.py +29 -0
  338. pcapkit/vendor/default.py +474 -0
  339. pcapkit/vendor/ftp/__init__.py +27 -0
  340. pcapkit/vendor/ftp/command.py +244 -0
  341. pcapkit/vendor/ftp/return_code.py +256 -0
  342. pcapkit/vendor/hip/__init__.py +94 -0
  343. pcapkit/vendor/hip/certificate.py +29 -0
  344. pcapkit/vendor/hip/cipher.py +29 -0
  345. pcapkit/vendor/hip/di.py +29 -0
  346. pcapkit/vendor/hip/ecdsa_curve.py +29 -0
  347. pcapkit/vendor/hip/ecdsa_low_curve.py +29 -0
  348. pcapkit/vendor/hip/eddsa_curve.py +85 -0
  349. pcapkit/vendor/hip/esp_transform_suite.py +29 -0
  350. pcapkit/vendor/hip/group.py +87 -0
  351. pcapkit/vendor/hip/hi_algorithm.py +29 -0
  352. pcapkit/vendor/hip/hit_suite.py +29 -0
  353. pcapkit/vendor/hip/nat_traversal.py +29 -0
  354. pcapkit/vendor/hip/notify_message.py +29 -0
  355. pcapkit/vendor/hip/packet.py +88 -0
  356. pcapkit/vendor/hip/parameter.py +88 -0
  357. pcapkit/vendor/hip/registration.py +29 -0
  358. pcapkit/vendor/hip/registration_failure.py +29 -0
  359. pcapkit/vendor/hip/suite.py +29 -0
  360. pcapkit/vendor/hip/transport.py +29 -0
  361. pcapkit/vendor/http/__init__.py +39 -0
  362. pcapkit/vendor/http/error_code.py +95 -0
  363. pcapkit/vendor/http/frame.py +91 -0
  364. pcapkit/vendor/http/method.py +167 -0
  365. pcapkit/vendor/http/setting.py +93 -0
  366. pcapkit/vendor/http/status_code.py +185 -0
  367. pcapkit/vendor/ipv4/__init__.py +57 -0
  368. pcapkit/vendor/ipv4/classification_level.py +91 -0
  369. pcapkit/vendor/ipv4/option_class.py +80 -0
  370. pcapkit/vendor/ipv4/option_number.py +105 -0
  371. pcapkit/vendor/ipv4/protection_authority.py +84 -0
  372. pcapkit/vendor/ipv4/qs_function.py +78 -0
  373. pcapkit/vendor/ipv4/router_alert.py +93 -0
  374. pcapkit/vendor/ipv4/tos_del.py +78 -0
  375. pcapkit/vendor/ipv4/tos_ecn.py +95 -0
  376. pcapkit/vendor/ipv4/tos_pre.py +84 -0
  377. pcapkit/vendor/ipv4/tos_rel.py +78 -0
  378. pcapkit/vendor/ipv4/tos_thr.py +77 -0
  379. pcapkit/vendor/ipv4/ts_flag.py +79 -0
  380. pcapkit/vendor/ipv6/__init__.py +53 -0
  381. pcapkit/vendor/ipv6/extension_header.py +171 -0
  382. pcapkit/vendor/ipv6/option.py +104 -0
  383. pcapkit/vendor/ipv6/option_action.py +90 -0
  384. pcapkit/vendor/ipv6/qs_function.py +78 -0
  385. pcapkit/vendor/ipv6/router_alert.py +93 -0
  386. pcapkit/vendor/ipv6/routing.py +87 -0
  387. pcapkit/vendor/ipv6/seed_id.py +81 -0
  388. pcapkit/vendor/ipv6/smf_dpd_mode.py +78 -0
  389. pcapkit/vendor/ipv6/tagger_id.py +81 -0
  390. pcapkit/vendor/ipx/__init__.py +37 -0
  391. pcapkit/vendor/ipx/packet.py +123 -0
  392. pcapkit/vendor/ipx/socket.py +125 -0
  393. pcapkit/vendor/l2tp/__init__.py +21 -0
  394. pcapkit/vendor/l2tp/type.py +78 -0
  395. pcapkit/vendor/mh/__init__.py +204 -0
  396. pcapkit/vendor/mh/access_type.py +87 -0
  397. pcapkit/vendor/mh/ack_status_code.py +88 -0
  398. pcapkit/vendor/mh/ani_suboption.py +88 -0
  399. pcapkit/vendor/mh/auth_subtype.py +83 -0
  400. pcapkit/vendor/mh/binding_ack_flag.py +148 -0
  401. pcapkit/vendor/mh/binding_error.py +78 -0
  402. pcapkit/vendor/mh/binding_revocation.py +87 -0
  403. pcapkit/vendor/mh/binding_update_flag.py +147 -0
  404. pcapkit/vendor/mh/cga_extension.py +91 -0
  405. pcapkit/vendor/mh/cga_sec.py +91 -0
  406. pcapkit/vendor/mh/cga_type.py +74 -0
  407. pcapkit/vendor/mh/dhcp_support_mode.py +77 -0
  408. pcapkit/vendor/mh/dns_status_code.py +87 -0
  409. pcapkit/vendor/mh/dsmip6_tls_packet.py +87 -0
  410. pcapkit/vendor/mh/dsmipv6_home_address.py +87 -0
  411. pcapkit/vendor/mh/enumerating_algorithm.py +82 -0
  412. pcapkit/vendor/mh/fb_ack_status.py +87 -0
  413. pcapkit/vendor/mh/fb_action.py +88 -0
  414. pcapkit/vendor/mh/fb_indication_trigger.py +87 -0
  415. pcapkit/vendor/mh/fb_type.py +88 -0
  416. pcapkit/vendor/mh/flow_id_status.py +87 -0
  417. pcapkit/vendor/mh/flow_id_suboption.py +87 -0
  418. pcapkit/vendor/mh/handoff_type.py +87 -0
  419. pcapkit/vendor/mh/handover_ack_flag.py +143 -0
  420. pcapkit/vendor/mh/handover_ack_status.py +87 -0
  421. pcapkit/vendor/mh/handover_initiate_flag.py +143 -0
  422. pcapkit/vendor/mh/handover_initiate_status.py +87 -0
  423. pcapkit/vendor/mh/home_address_reply.py +87 -0
  424. pcapkit/vendor/mh/lla_code.py +97 -0
  425. pcapkit/vendor/mh/lma_mag_suboption.py +88 -0
  426. pcapkit/vendor/mh/mn_group_id.py +87 -0
  427. pcapkit/vendor/mh/mn_id_subtype.py +87 -0
  428. pcapkit/vendor/mh/operator_id.py +87 -0
  429. pcapkit/vendor/mh/option.py +83 -0
  430. pcapkit/vendor/mh/packet.py +82 -0
  431. pcapkit/vendor/mh/qos_attribute.py +87 -0
  432. pcapkit/vendor/mh/revocation_status_code.py +87 -0
  433. pcapkit/vendor/mh/revocation_trigger.py +87 -0
  434. pcapkit/vendor/mh/status_code.py +91 -0
  435. pcapkit/vendor/mh/traffic_selector.py +87 -0
  436. pcapkit/vendor/mh/upa_status.py +87 -0
  437. pcapkit/vendor/mh/upn_reason.py +87 -0
  438. pcapkit/vendor/ospf/__init__.py +27 -0
  439. pcapkit/vendor/ospf/authentication.py +29 -0
  440. pcapkit/vendor/ospf/packet.py +29 -0
  441. pcapkit/vendor/pcapng/__init__.py +51 -0
  442. pcapkit/vendor/pcapng/block_type.py +94 -0
  443. pcapkit/vendor/pcapng/filter_type.py +77 -0
  444. pcapkit/vendor/pcapng/hash_algorithm.py +82 -0
  445. pcapkit/vendor/pcapng/option_type.py +287 -0
  446. pcapkit/vendor/pcapng/record_type.py +81 -0
  447. pcapkit/vendor/pcapng/secrets_type.py +81 -0
  448. pcapkit/vendor/pcapng/verdict_type.py +79 -0
  449. pcapkit/vendor/reg/__init__.py +34 -0
  450. pcapkit/vendor/reg/apptype.py +338 -0
  451. pcapkit/vendor/reg/ethertype.py +121 -0
  452. pcapkit/vendor/reg/linktype.py +110 -0
  453. pcapkit/vendor/reg/transtype.py +111 -0
  454. pcapkit/vendor/tcp/__init__.py +35 -0
  455. pcapkit/vendor/tcp/checksum.py +80 -0
  456. pcapkit/vendor/tcp/flags.py +149 -0
  457. pcapkit/vendor/tcp/mp_tcp_option.py +90 -0
  458. pcapkit/vendor/tcp/option.py +103 -0
  459. pcapkit/vendor/vlan/__init__.py +23 -0
  460. pcapkit/vendor/vlan/priority_level.py +97 -0
  461. pypcapkit-1.3.5.post6.dist-info/LICENSE +29 -0
  462. pypcapkit-1.3.5.post6.dist-info/METADATA +238 -0
  463. pypcapkit-1.3.5.post6.dist-info/RECORD +466 -0
  464. pypcapkit-1.3.5.post6.dist-info/WHEEL +5 -0
  465. pypcapkit-1.3.5.post6.dist-info/entry_points.txt +3 -0
  466. pypcapkit-1.3.5.post6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1689 @@
1
+ # -*- coding: utf-8 -*-
2
+ # mypy: disable-error-code=assignment
3
+ """header schema for pcapng file format"""
4
+
5
+ import base64
6
+ import collections
7
+ import collections.abc
8
+ import io
9
+ import struct
10
+ import sys
11
+ from typing import TYPE_CHECKING, Any, cast
12
+
13
+ from pcapkit.const.pcapng.block_type import BlockType as Enum_BlockType
14
+ from pcapkit.const.pcapng.filter_type import FilterType as Enum_FilterType
15
+ from pcapkit.const.pcapng.hash_algorithm import HashAlgorithm as Enum_HashAlgorithm
16
+ from pcapkit.const.pcapng.option_type import OptionType as Enum_OptionType
17
+ from pcapkit.const.pcapng.record_type import RecordType as Enum_RecordType
18
+ from pcapkit.const.pcapng.secrets_type import SecretsType as Enum_SecretsType
19
+ from pcapkit.const.pcapng.verdict_type import VerdictType as Enum_VerdictType
20
+ from pcapkit.const.reg.linktype import LinkType as Enum_LinkType
21
+ from pcapkit.corekit.fields.collections import OptionField
22
+ from pcapkit.corekit.fields.ipaddress import (IPv4AddressField, IPv4InterfaceField,
23
+ IPv6AddressField, IPv6InterfaceField)
24
+ from pcapkit.corekit.fields.misc import ForwardMatchField, PayloadField, SchemaField, SwitchField
25
+ from pcapkit.corekit.fields.numbers import (EnumField, Int32Field, Int64Field, NumberField,
26
+ UInt8Field, UInt16Field, UInt32Field, UInt64Field)
27
+ from pcapkit.corekit.fields.strings import BitField, BytesField, PaddingField, StringField
28
+ from pcapkit.corekit.multidict import MultiDict, OrderedMultiDict
29
+ from pcapkit.protocols.schema.schema import EnumSchema, Schema, schema_final
30
+ from pcapkit.utilities.exceptions import FieldValueError, ProtocolError, stacklevel
31
+ from pcapkit.utilities.logging import SPHINX_TYPE_CHECKING
32
+ from pcapkit.utilities.warnings import ProtocolWarning, warn
33
+
34
+ __all__ = [
35
+ 'PCAPNG',
36
+
37
+ 'Option', 'UnknownOption',
38
+ 'EndOfOption', 'CommentOption', 'CustomOption',
39
+ 'IF_NameOption', 'IF_DescriptionOption', 'IF_IPv4AddrOption', 'IF_IPv6AddrOption',
40
+ 'IF_MACAddrOption', 'IF_EUIAddrOption', 'IF_SpeedOption', 'IF_TSResolOption',
41
+ 'IF_TZoneOption', 'IF_FilterOption', 'IF_OSOption', 'IF_FCSLenOption',
42
+ 'IF_TSOffsetOption', 'IF_HardwareOption', 'IF_TxSpeedOption', 'IF_RxSpeedOption',
43
+ 'EPB_FlagsOption', 'EPB_HashOption', 'EPB_DropCountOption', 'EPB_PacketIDOption',
44
+ 'EPB_QueueOption', 'EPB_VerdictOption',
45
+ 'NS_DNSNameOption', 'NS_DNSIP4AddrOption', 'NS_DNSIP6AddrOption',
46
+ 'ISB_StartTimeOption', 'ISB_EndTimeOption', 'ISB_IFRecvOption', 'ISB_IFDropOption',
47
+ 'ISB_FilterAcceptOption', 'ISB_OSDropOption', 'ISB_UsrDelivOption',
48
+ 'PACK_FlagsOption', 'PACK_HashOption',
49
+
50
+ 'NameResolutionRecord', 'UnknownRecord', 'EndRecord', 'IPv4Record', 'IPv6Record',
51
+
52
+ 'DSBSecrets', 'UnknownSecrets', 'TLSKeyLog', 'WireGuardKeyLog', 'ZigBeeNWKKey',
53
+ 'ZigBeeAPSKey',
54
+
55
+ 'BlockType',
56
+ 'UnknownBlock', 'SectionHeaderBlock', 'InterfaceDescriptionBlock',
57
+ 'EnhancedPacketBlock', 'SimplePacketBlock', 'NameResolutionBlock',
58
+ 'InterfaceStatisticsBlock', 'SystemdJournalExportBlock', 'DecryptionSecretsBlock',
59
+ 'CustomBlock', 'PacketBlock',
60
+ ]
61
+
62
+ if TYPE_CHECKING:
63
+ from ipaddress import IPv4Address, IPv4Interface, IPv6Address, IPv6Interface
64
+ from typing import Any, Callable, DefaultDict, Iterable, Optional, Type
65
+
66
+ from typing_extensions import Literal, Self
67
+
68
+ from pcapkit.corekit.fields.field import FieldBase as Field
69
+ from pcapkit.protocols.misc.pcapng import TLSKeyLabel, WireGuardKeyLabel
70
+ from pcapkit.protocols.protocol import ProtocolBase as Protocol
71
+
72
+ if SPHINX_TYPE_CHECKING:
73
+ from typing_extensions import TypedDict
74
+
75
+ class ByteorderTest(TypedDict):
76
+ """Test for byteorder."""
77
+
78
+ #: Byteorder magic number.
79
+ byteorder: int
80
+
81
+ class ResolutionData(TypedDict):
82
+ """Data for resolution."""
83
+
84
+ #: Resolution type flag (0: 10-based, 1: 2-based).
85
+ flag: int
86
+ #: Resolution value.
87
+ resolution: int
88
+
89
+ class EPBFlags(TypedDict):
90
+ """EPB flags."""
91
+
92
+ #: Inbound / Outbound packet (``00`` = information not available,
93
+ #: ``01`` = inbound, ``10`` = outbound)
94
+ direction: int
95
+ #: Reception type (``000`` = not specified, ``001`` = unicast,
96
+ #: ``010`` = multicast, ``011`` = broadcast, ``100`` = promiscuous).
97
+ reception: int
98
+ #: FCS length, in octets (``0000`` if this information is not available).
99
+ #: This value overrides the ``if_fcslen`` option of the Interface Description
100
+ #: Block, and is used with those link layers (e.g. PPP) where the length of
101
+ #: the FCS can change during time.
102
+ fcs_len: int
103
+ #: Link-layer-dependent error - CRC error (bit 24).
104
+ crc_error: int
105
+ #: Link-layer-dependent error - packet too long error (bit 25).
106
+ too_long: int
107
+ #: Link-layer-dependent error - packet too short error (bit 26).
108
+ too_short: int
109
+ #: Link-layer-dependent error - wrong Inter Frame Gap error (bit 27).
110
+ gap_error: int
111
+ #: Link-layer-dependent error - unaligned frame error (bit 28).
112
+ unaligned_error: int
113
+ #: Link-layer-dependent error - Start Frame Delimiter error (bit 29).
114
+ delimiter_error: int
115
+ #: Link-layer-dependent error - preamble error (bit 30).
116
+ preamble_error: int
117
+ #: Link-layer-dependent error - symbol error (bit 31).
118
+ symbol_error: int
119
+
120
+ class PACKFlags(TypedDict):
121
+ """PACK flags."""
122
+
123
+ #: Inbound / Outbound packet (``00`` = information not available,
124
+ #: ``01`` = inbound, ``10`` = outbound)
125
+ direction: int
126
+ #: Reception type (``000`` = not specified, ``001`` = unicast,
127
+ #: ``010`` = multicast, ``011`` = broadcast, ``100`` = promiscuous).
128
+ reception: int
129
+ #: FCS length, in octets (``0000`` if this information is not available).
130
+ #: This value overrides the ``if_fcslen`` option of the Interface Description
131
+ #: Block, and is used with those link layers (e.g. PPP) where the length of
132
+ #: the FCS can change during time.
133
+ fcs_len: int
134
+ #: Link-layer-dependent error - CRC error (bit 24).
135
+ crc_error: int
136
+ #: Link-layer-dependent error - packet too long error (bit 25).
137
+ too_long: int
138
+ #: Link-layer-dependent error - packet too short error (bit 26).
139
+ too_short: int
140
+ #: Link-layer-dependent error - wrong Inter Frame Gap error (bit 27).
141
+ gap_error: int
142
+ #: Link-layer-dependent error - unaligned frame error (bit 28).
143
+ unaligned_error: int
144
+ #: Link-layer-dependent error - Start Frame Delimiter error (bit 29).
145
+ delimiter_error: int
146
+ #: Link-layer-dependent error - preamble error (bit 30).
147
+ preamble_error: int
148
+ #: Link-layer-dependent error - symbol error (bit 31).
149
+ symbol_error: int
150
+
151
+
152
+ def byteorder_callback(field: 'NumberField', packet: 'dict[str, Any]') -> 'None':
153
+ """Update byte order of PCAP-NG file.
154
+
155
+ Args:
156
+ field: Field instance.
157
+ packet: Packet data.
158
+
159
+ """
160
+ if 'byteorder' not in packet and '__packet__' in packet:
161
+ field._byteorder = packet['__packet__'].get('byteorder', sys.byteorder)
162
+ else:
163
+ field._byteorder = packet.get('byteorder', sys.byteorder)
164
+
165
+
166
+ def shb_byteorder_callback(field: 'NumberField', packet: 'dict[str, Any]') -> 'None':
167
+ """Update byte order of PCAP-NG file for SHB.
168
+
169
+ Args:
170
+ field: Field instance.
171
+ packet: Packet data.
172
+
173
+ """
174
+ magic = packet['match']['byteorder'] # type: int
175
+ if magic == 0x1A2B3C4D:
176
+ field._byteorder = 'big'
177
+ elif magic == 0x4D3C2B1A:
178
+ field._byteorder = 'little'
179
+ else:
180
+ raise ProtocolError(f'unknown byteorder magic: {magic:#x}')
181
+
182
+
183
+ def pcapng_block_selector(packet: 'dict[str, Any]') -> 'Field':
184
+ """Selector function for :attr:`PCAPNG.block` field.
185
+
186
+ Args:
187
+ pkt: Packet data.
188
+
189
+ Returns:
190
+ Returns a :class:`~pcapkit.corekit.fields.misc.SchemaField`
191
+ wrapped :class:`~pcapkit.protocols.schema.misc.pcapng.BlockType`
192
+ subclass instance.
193
+
194
+ See Also:
195
+ * :class:`pcapkit.const.pcapng.block_type.BlockType`
196
+ * :class:`pcapkit.protocols.schema.misc.pcapng.BlockType`
197
+
198
+ """
199
+ block_type = packet['type'] # type: Enum_BlockType
200
+ schema = BlockType.registry[block_type]
201
+ return SchemaField(length=packet['__length__'], schema=schema)
202
+
203
+
204
+ def dsb_secrets_selector(packet: 'dict[str, Any]') -> 'Field':
205
+ """Selector function for :attr:`DecryptionSecretsBlock.secrets_data` field.
206
+
207
+ Args:
208
+ pkt: Packet data.
209
+
210
+ Returns:
211
+ * If ``secrets_type`` is unknown, returns a
212
+ :class:`~pcapkit.corekit.fields.strings.BytesField` instance.
213
+ * If ``secret_type`` is :attr:`~pcapkit.const.pcapng.secrets_type.Secrets_Type.TLS_Key_Log`
214
+ and/or :attr:`~pcapkit.const.pcapng.secrets_type.Secrets_Type.WireGuard_Key_Log`,
215
+ returns a :class:`~pcapkit.corekit.fields.strings.StringField` instance.
216
+ * Otherwise, returns a :class:`~pcapkit.corekit.fields.misc.SchemaField`
217
+ wrapped :class:`~pcapkit.protocols.schema.misc.pcapng.DSBSecrets`
218
+ subclass instance.
219
+
220
+ See Also:
221
+ * :class:`pcapkit.const.pcapng.secrets_type.Secrets_Type`
222
+ * :class:`pcapkit.protocols.schema.misc.pcapng.DSBSecrets`
223
+
224
+ """
225
+ secrets_type = packet['secrets_type'] # type: int
226
+ schema = DSBSecrets.registry[secrets_type]
227
+ return SchemaField(length=packet['secrets_length'], schema=schema)
228
+
229
+
230
+ class OptionEnumField(EnumField):
231
+ """Enumerated value for protocol fields.
232
+
233
+ Args:
234
+ length: Field size (in bytes); if a callable is given, it should return
235
+ an integer value and accept the current packet as its only argument.
236
+ default: Field default value, if any.
237
+ signed: Whether the field is signed.
238
+ byteorder: Field byte order.
239
+ bit_length: Field bit length.
240
+ namespace: Option namespace, i.e., namespace of the enum item.
241
+ callback: Callback function to be called upon
242
+ :meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
243
+
244
+ Important:
245
+ This class is specifically designed for :class:`~pcapkit.const.pcapng.option_type.OptionType`
246
+ as it is actually a :class:`~enum.StrEnum` class.
247
+
248
+ """
249
+ if TYPE_CHECKING:
250
+ _namespace: 'Enum_OptionType'
251
+
252
+ def __init__(self, length: 'int | Callable[[dict[str, Any]], int]',
253
+ default: 'Enum_OptionType' = Enum_OptionType.opt_endofopt, signed: 'bool' = False,
254
+ byteorder: 'Literal["little", "big"]' = 'big',
255
+ bit_length: 'Optional[int]' = None,
256
+ namespace: 'str' = 'opt',
257
+ callback: 'Callable[[Self, dict[str, Any]], None]' = lambda *_: None) -> 'None':
258
+ super().__init__(length, default, signed, byteorder, bit_length, Enum_OptionType, callback)
259
+
260
+ self._opt_ns = namespace
261
+
262
+ def pre_process(self, value: 'int | Enum_OptionType', packet: 'dict[str, Any]') -> 'int | bytes':
263
+ """Process field value before construction (packing).
264
+
265
+ Arguments:
266
+ value: Field value.
267
+ packet: Packet data.
268
+
269
+ Returns:
270
+ Processed field value.
271
+
272
+ """
273
+ if isinstance(value, Enum_OptionType):
274
+ value = value.opt_value
275
+ return super().pre_process(value, packet)
276
+
277
+ def post_process(self, value: 'int | bytes', packet: 'dict[str, Any]') -> 'Enum_OptionType':
278
+ """Process field value after parsing (unpacked).
279
+
280
+ Args:
281
+ value: Field value.
282
+ packet: Packet data.
283
+
284
+ Returns:
285
+ Processed field value.
286
+
287
+ """
288
+ value = super(EnumField, self).post_process(value, packet)
289
+ return self._namespace.get(value, namespace=self._opt_ns)
290
+
291
+
292
+ @schema_final
293
+ class PCAPNG(Schema):
294
+ """Header schema for PCAP-NG file blocks."""
295
+
296
+ #: Block type.
297
+ type: 'Enum_BlockType' = EnumField(length=4, namespace=Enum_BlockType, callback=byteorder_callback)
298
+ #: Block specific data.
299
+ block: 'BlockType' = SwitchField(
300
+ selector=pcapng_block_selector,
301
+ )
302
+
303
+ if TYPE_CHECKING:
304
+ def __init__(self, type: 'Enum_BlockType', block: 'BlockType | bytes') -> 'None': ...
305
+
306
+
307
+ class BlockType(EnumSchema[Enum_BlockType]):
308
+ """Header schema for PCAP-NG file blocks."""
309
+
310
+ __default__ = lambda: UnknownBlock
311
+
312
+ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
313
+ """Revise ``schema`` data after unpacking process.
314
+
315
+ This method validates the two block lengths and raises
316
+ :exc:`~pcapkit.utilities.exceptions.ProtocolError` if they are not
317
+ equal.
318
+
319
+ Args:
320
+ packet: Unpacked data.
321
+
322
+ Returns:
323
+ Revised schema.
324
+
325
+ """
326
+ if self.length != self.length2:
327
+ block_type = packet.get('__packet__', {}).get('type', 'N/A')
328
+ #raise ProtocolError(f'PCAP-NG: [Block {block_type}] block length mismatch: {self.length} != {self.length2}')
329
+ warn(f'PCAP-NG: [Block {block_type}] block length mismatch: {self.length} != {self.length2}',
330
+ ProtocolWarning, stacklevel=stacklevel())
331
+ return self
332
+
333
+ if TYPE_CHECKING:
334
+ length: int
335
+ length2: int
336
+
337
+
338
+ @schema_final
339
+ class UnknownBlock(BlockType):
340
+ """Header schema for unknown PCAP-NG file blocks."""
341
+
342
+ #: Block total length.
343
+ length: 'int' = UInt32Field(callback=byteorder_callback)
344
+ #: Block body (including padding).
345
+ body: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 12)
346
+ #: Block total length.
347
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
348
+
349
+ if TYPE_CHECKING:
350
+ def __init__(self, length: 'int', body: 'bytes', length2: 'int') -> 'None': ...
351
+
352
+
353
+ class Option(EnumSchema[Enum_OptionType]):
354
+ """Header schema for PCAP-NG file options."""
355
+
356
+ __additional__ = ['__enum__', '__namespace__']
357
+ __excluded__ = ['__enum__', '__namespace__']
358
+
359
+ #: Namespace of PCAP-NG option type numbers.
360
+ __namespace__: 'str' = None # type: ignore[assignment]
361
+ #: Mapping of PCAP-NG option type numbers to schemas.
362
+ __enum__: 'DefaultDict[str, DefaultDict[Enum_OptionType, Type[Option]]]' = collections.defaultdict(
363
+ lambda: Option.registry['opt'], {
364
+ 'opt': collections.defaultdict(lambda: UnknownOption),
365
+ 'if': collections.defaultdict(lambda: UnknownOption),
366
+ 'epb': collections.defaultdict(lambda: UnknownOption),
367
+ 'ns': collections.defaultdict(lambda: UnknownOption),
368
+ 'isb': collections.defaultdict(lambda: UnknownOption),
369
+ 'dsb': collections.defaultdict(lambda: UnknownOption),
370
+ 'pack': collections.defaultdict(lambda: UnknownOption),
371
+ },
372
+ )
373
+
374
+ def __init_subclass__(cls, /, code: 'Optional[Enum_OptionType | Iterable[Enum_OptionType]]' = None,
375
+ namespace: 'Optional[str]' = None, *args: 'Any', **kwargs: 'Any') -> 'None':
376
+ """Register option type to :attr:`__enum__` mapping.
377
+
378
+ Args:
379
+ code: Option type code. It can be either a single option type enumeration
380
+ or a list of option type enumerations.
381
+ namespace: Namespace of option type enumeration. If not given, the value
382
+ will be inferred from the option type code.
383
+ *args: Arbitrary positional arguments.
384
+ **kwargs: Arbitrary keyword arguments.
385
+
386
+ If ``code`` is provided, the subclass will be registered to the
387
+ :attr:`__enum__` mapping with the given ``code``. If ``code`` is
388
+ not given, the subclass will not be registered.
389
+
390
+ Examples:
391
+
392
+ .. code-block:: python
393
+
394
+ from pcapkit.const.pcapng.option_type import OptionType as Enum_OptionType
395
+ from pcapkit.protocols.schema.misc.pcapng improt Option
396
+
397
+ class NewOption(Option, namespace='opt', code=Enum_OptionType.opt_new):
398
+ ...
399
+
400
+ See Also:
401
+ - :class:`pcapkit.const.pcapng.option_type.OptionType`
402
+
403
+ """
404
+ if namespace is not None:
405
+ cls.__namespace__ = namespace
406
+
407
+ if code is not None:
408
+ if namespace is None:
409
+ namespace = cast('Optional[str]', cls.__namespace__)
410
+
411
+ if not isinstance(code, Enum_OptionType):
412
+ for _code in code:
413
+ Option.register(_code, cls, namespace)
414
+ else:
415
+ Option.register(code, cls, namespace)
416
+ super().__init_subclass__()
417
+
418
+ @staticmethod
419
+ def register(code: 'Enum_OptionType', cls: 'Type[Option]', ns: 'Optional[str]' = None) -> 'None':
420
+ """Register option type to :attr:`__enum__` mapping.
421
+
422
+ Args:
423
+ code: Option type code.
424
+ cls: Option type schema.
425
+ ns: Namespace of option type enumeration. If not given, the value
426
+ will be inferred from the option type code.
427
+
428
+ """
429
+ if ns is None:
430
+ ns = code.name.split('_')[0]
431
+
432
+ if ns == 'opt':
433
+ for key in Option.registry:
434
+ Option.registry[key][code] = cls
435
+ elif ns in Option.registry:
436
+ Option.registry[ns][code] = cls
437
+ else:
438
+ Option.registry[ns] = Option.registry['opt'].copy()
439
+ Option.registry[ns][code] = cls
440
+
441
+ if TYPE_CHECKING:
442
+ #: Option type.
443
+ type: 'Enum_OptionType'
444
+ #: Option data length.
445
+ length: 'int'
446
+
447
+
448
+ class _OPT_Option(Option, namespace='opt'):
449
+ """Header schema for ``opt_*`` options."""
450
+
451
+ #: Option type.
452
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='opt', callback=byteorder_callback)
453
+ #: Option data length.
454
+ length: 'int' = UInt16Field(callback=byteorder_callback)
455
+
456
+
457
+ @schema_final
458
+ class UnknownOption(_OPT_Option):
459
+ """Header schema for unknown PCAP-NG file options."""
460
+
461
+ #: Option value.
462
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['length'])
463
+ #: Padding.
464
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
465
+
466
+ if TYPE_CHECKING:
467
+ def __init__(self, type: 'Enum_OptionType', length: 'int', data: 'bytes') -> 'None': ...
468
+
469
+
470
+ @schema_final
471
+ class EndOfOption(_OPT_Option, code=Enum_OptionType.opt_endofopt):
472
+ """Header schema for PCAP-NG file ``opt_endofopt`` options."""
473
+
474
+ if TYPE_CHECKING:
475
+ def __init__(self, type: 'Enum_OptionType', length: 'int') -> 'None': ...
476
+
477
+
478
+ @schema_final
479
+ class CommentOption(_OPT_Option, code=Enum_OptionType.opt_comment):
480
+ """Header schema for PCAP-NG file ``opt_comment`` options."""
481
+
482
+ #: Comment text.
483
+ comment: 'str' = StringField(length=lambda pkt: pkt['length'], encoding='utf-8')
484
+ #: Padding.
485
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
486
+
487
+ if TYPE_CHECKING:
488
+ def __init__(self, type: 'Enum_OptionType', length: 'int', comment: 'str') -> 'None': ...
489
+
490
+
491
+ @schema_final
492
+ class CustomOption(_OPT_Option, code=[Enum_OptionType.opt_custom_2988,
493
+ Enum_OptionType.opt_custom_2989,
494
+ Enum_OptionType.opt_custom_19372,
495
+ Enum_OptionType.opt_custom_19373]):
496
+ """Header schema for PCAP-NG file ``opt_custom`` options."""
497
+
498
+ #: Private enterprise number (PEN).
499
+ pen: 'int' = UInt32Field(callback=byteorder_callback)
500
+ #: Custom data.
501
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 4)
502
+ #: Padding.
503
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
504
+
505
+ if TYPE_CHECKING:
506
+ def __init__(self, type: 'int', length: 'int', pen: 'int', data: 'bytes') -> 'None': ...
507
+
508
+
509
+ @schema_final
510
+ class SectionHeaderBlock(BlockType, code=Enum_BlockType.Section_Header_Block):
511
+ """Header schema for PCAP-NG Section Header Block (SHB)."""
512
+
513
+ #: Fast forward field to test the byteorder.
514
+ match: 'ByteorderTest' = ForwardMatchField(BitField(length=8, namespace={
515
+ 'byteorder': (32, 32),
516
+ }))
517
+ #: Block total length.
518
+ length: 'int' = UInt32Field(callback=shb_byteorder_callback)
519
+ #: Byte order magic number.
520
+ magic: 'Literal[0x1A2B3C4D]' = UInt32Field(callback=shb_byteorder_callback)
521
+ #: Major version number.
522
+ major: 'int' = UInt16Field(callback=shb_byteorder_callback, default=1)
523
+ #: Minor version number.
524
+ minor: 'int' = UInt16Field(callback=shb_byteorder_callback, default=0)
525
+ #: Section length.
526
+ section_length: 'int' = Int64Field(callback=shb_byteorder_callback, default=0xFFFF_FFFF_FFFF_FFFF)
527
+ #: Options.
528
+ options: 'list[Option]' = OptionField(
529
+ length=lambda pkt: pkt['length'] - 28,
530
+ base_schema=_OPT_Option,
531
+ type_name='type',
532
+ registry=Option.registry['opt'],
533
+ eool=Enum_OptionType.opt_endofopt,
534
+ )
535
+ #: Padding.
536
+ padding: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
537
+ #: Block total length.
538
+ length2: 'int' = UInt32Field(callback=shb_byteorder_callback)
539
+
540
+ def pre_pack(self, packet: 'dict[str, Any]') -> 'None':
541
+ """Prepare ``packet`` data for packing process.
542
+
543
+ Args:
544
+ packet: packet data
545
+
546
+ Note:
547
+ This method is expected to directly modify any data stored
548
+ in the ``packet`` and thus no return is required.
549
+
550
+ """
551
+ if 'match' in packet:
552
+ return
553
+
554
+ packet['match'] = {
555
+ 'byteorder': 0x1A2B3C4D if sys.byteorder == 'big' else 0x4D3C2B1A,
556
+ }
557
+
558
+ def post_process(self, packet: 'dict[str, Any]') -> 'SectionHeaderBlock':
559
+ """Revise ``schema`` data after unpacking process.
560
+
561
+ This method calculate the byteorder value based on
562
+ the parsed schema.
563
+
564
+ Args:
565
+ packet: Unpacked data.
566
+
567
+ Returns:
568
+ Revised schema.
569
+
570
+ """
571
+ self = cast('Self', super().post_process(packet))
572
+
573
+ if self.section_length == 0xFFFF_FFFF_FFFF_FFFF:
574
+ self.section_length = -1
575
+
576
+ magic = packet['match']['byteorder'] # type: int
577
+ if magic == 0x1A2B3C4D:
578
+ self.byteorder = 'big'
579
+ elif magic == 0x4D3C2B1A:
580
+ self.byteorder = 'little'
581
+ else:
582
+ raise ProtocolError(f'unknown byteorder magic: {magic:#x}')
583
+ return self
584
+
585
+ if TYPE_CHECKING:
586
+ #: Byteorder.
587
+ byteorder: Literal['big', 'little']
588
+
589
+ def __init__(self, length: 'int', magic: 'Literal[0x1A2B3C4D]', major: 'int',
590
+ minor: 'int', section_length: 'int', options: 'list[Option | bytes] | bytes',
591
+ length2: 'int') -> 'None': ...
592
+
593
+
594
+ class _IF_Option(Option, namespace='if'):
595
+ """Header schema for ``if_*`` options."""
596
+
597
+ #: Option type.
598
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='if', callback=byteorder_callback)
599
+ #: Option data length.
600
+ length: 'int' = UInt16Field(callback=byteorder_callback)
601
+
602
+
603
+ @schema_final
604
+ class IF_NameOption(_IF_Option, code=Enum_OptionType.if_name):
605
+ """Header schema for PCAP-NG file ``if_name`` options."""
606
+
607
+ #: Interface name.
608
+ name: 'str' = StringField(length=lambda pkt: pkt['length'], encoding='utf-8')
609
+ #: Padding.
610
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
611
+
612
+ if TYPE_CHECKING:
613
+ def __init__(self, type: 'Enum_OptionType', length: 'int', name: 'str') -> 'None': ...
614
+
615
+
616
+ @schema_final
617
+ class IF_DescriptionOption(_IF_Option, code=Enum_OptionType.if_description):
618
+ """Header schema for PCAP-NG file ``if_description`` options."""
619
+
620
+ #: Interface description.
621
+ description: 'str' = StringField(length=lambda pkt: pkt['length'], encoding='utf-8')
622
+ #: Padding.
623
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
624
+
625
+ if TYPE_CHECKING:
626
+ def __init__(self, type: 'Enum_OptionType', length: 'int', description: 'str') -> 'None': ...
627
+
628
+
629
+ @schema_final
630
+ class IF_IPv4AddrOption(_IF_Option, code=Enum_OptionType.if_IPv4addr):
631
+ """Header schema for PCAP-NG file ``if_IPv4addr`` options."""
632
+
633
+ #: IPv4 interface.
634
+ interface: 'IPv4Interface' = IPv4InterfaceField()
635
+ #: Padding.
636
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
637
+
638
+ if TYPE_CHECKING:
639
+ def __init__(self, type: 'Enum_OptionType', length: 'int', interface: 'IPv4Interface | str') -> 'None': ...
640
+
641
+
642
+ @schema_final
643
+ class IF_IPv6AddrOption(_IF_Option, code=Enum_OptionType.if_IPv6addr):
644
+ """Header schema for PCAP-NG file ``if_IPv6addr`` options."""
645
+
646
+ #: IPv6 interface.
647
+ interface: 'IPv6Interface' = IPv6InterfaceField()
648
+ #: Padding.
649
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
650
+
651
+ if TYPE_CHECKING:
652
+ def __init__(self, type: 'Enum_OptionType', length: 'int', interface: 'IPv6Interface | str') -> 'None': ...
653
+
654
+
655
+ @schema_final
656
+ class IF_MACAddrOption(_IF_Option, code=Enum_OptionType.if_MACaddr):
657
+ """Header schema for PCAP-NG file ``if_MACaddr`` options."""
658
+
659
+ #: MAC interface.
660
+ interface: 'bytes' = BytesField(length=6)
661
+ #: Padding.
662
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
663
+
664
+ if TYPE_CHECKING:
665
+ def __init__(self, type: 'Enum_OptionType', length: 'int', interface: 'bytes') -> 'None': ...
666
+
667
+
668
+ @schema_final
669
+ class IF_EUIAddrOption(_IF_Option, code=Enum_OptionType.if_EUIaddr):
670
+ """Header schema for PCAP-NG file ``if_EUIaddr`` options."""
671
+
672
+ #: EUI interface.
673
+ interface: 'bytes' = BytesField(length=8)
674
+ #: Padding.
675
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
676
+
677
+ if TYPE_CHECKING:
678
+ def __init__(self, type: 'Enum_OptionType', length: 'int', interface: 'bytes') -> 'None': ...
679
+
680
+
681
+ @schema_final
682
+ class IF_SpeedOption(_IF_Option, code=Enum_OptionType.if_speed):
683
+ """Header schema for PCAP-NG file ``if_speed`` options."""
684
+
685
+ #: Interface speed, in bits per second.
686
+ speed: 'int' = UInt64Field(callback=byteorder_callback)
687
+ #: Padding.
688
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
689
+
690
+ if TYPE_CHECKING:
691
+ def __init__(self, type: 'Enum_OptionType', length: 'int', speed: 'int') -> 'None': ...
692
+
693
+
694
+ @schema_final
695
+ class IF_TSResolOption(_IF_Option, code=Enum_OptionType.if_tsresol):
696
+ """Header schema for PCAP-NG file ``if_tsresol`` options."""
697
+
698
+ #: Interface timestamp resolution, in units per second.
699
+ tsresol: 'ResolutionData' = BitField(length=1, namespace={
700
+ 'flag': (0, 1),
701
+ 'resolution': (1, 7),
702
+ })
703
+ #: Padding.
704
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
705
+
706
+ def post_process(self, packet: 'dict[str, Any]') -> 'IF_TSResolOption':
707
+ """Revise ``schema`` data after unpacking process.
708
+
709
+ Args:
710
+ packet: Unpacked data.
711
+
712
+ Returns:
713
+ Revised schema.
714
+
715
+ """
716
+ base = 10 if self.tsresol['flag'] == 0 else 2
717
+ self.resolution = base ** self.tsresol['resolution']
718
+ return self
719
+
720
+ if TYPE_CHECKING:
721
+ #: Interface timestamp resolution, in units per second.
722
+ resolution: 'int'
723
+
724
+ def __init__(self, type: 'Enum_OptionType', length: 'int', tsresol: 'ResolutionData') -> 'None': ...
725
+
726
+
727
+ @schema_final
728
+ class IF_TZoneOption(_IF_Option, code=Enum_OptionType.if_tzone):
729
+ """Header schema for PCAP-NG file ``if_tzone`` options."""
730
+
731
+ #: Interface time zone (as in seconds difference from GMT).
732
+ tzone: 'int' = Int32Field(callback=byteorder_callback)
733
+ #: Padding.
734
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
735
+
736
+ if TYPE_CHECKING:
737
+ def __init__(self, type: 'Enum_OptionType', length: 'int', tzone: 'int') -> 'None': ...
738
+
739
+
740
+ @schema_final
741
+ class IF_FilterOption(_IF_Option, code=Enum_OptionType.if_filter):
742
+ """Header schema for PCAP-NG file ``if_filter`` options."""
743
+
744
+ #: Filter code.
745
+ code: 'Enum_FilterType' = EnumField(length=1, namespace=Enum_FilterType, callback=byteorder_callback)
746
+ #: Capture filter.
747
+ filter: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 1)
748
+ #: Padding.
749
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
750
+
751
+ if TYPE_CHECKING:
752
+ def __init__(self, type: 'Enum_OptionType', length: 'int', code: 'Enum_FilterType', filter: 'bytes') -> 'None': ...
753
+
754
+
755
+ @schema_final
756
+ class IF_OSOption(_IF_Option, code=Enum_OptionType.if_os):
757
+ """Header schema for PCAP-NG file ``if_os`` options."""
758
+
759
+ #: OS information.
760
+ os: 'str' = StringField(length=lambda pkt: pkt['length'], encoding='utf-8')
761
+ #: Padding.
762
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
763
+
764
+ if TYPE_CHECKING:
765
+ def __init__(self, type: 'Enum_OptionType', length: 'int', os: 'str') -> 'None': ...
766
+
767
+
768
+ @schema_final
769
+ class IF_FCSLenOption(_IF_Option, code=Enum_OptionType.if_fcslen):
770
+ """Header schema for PCAP-NG file ``if_fcslen`` options."""
771
+
772
+ #: FCS length.
773
+ fcslen: 'int' = UInt8Field(callback=byteorder_callback)
774
+ #: Padding.
775
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
776
+
777
+ if TYPE_CHECKING:
778
+ def __init__(self, type: 'Enum_OptionType', length: 'int', fcslen: 'int') -> 'None': ...
779
+
780
+
781
+ @schema_final
782
+ class IF_TSOffsetOption(_IF_Option, code=Enum_OptionType.if_tsoffset):
783
+ """Header schema for PCAP-NG file ``if_tsoffset`` options."""
784
+
785
+ #: Timestamp offset (in seconds).
786
+ tsoffset: 'int' = Int64Field(callback=byteorder_callback)
787
+ #: Padding.
788
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
789
+
790
+ if TYPE_CHECKING:
791
+ def __init__(self, type: 'Enum_OptionType', length: 'int', tsoffset: 'int') -> 'None': ...
792
+
793
+
794
+ @schema_final
795
+ class IF_HardwareOption(_IF_Option, code=Enum_OptionType.if_hardware):
796
+ """Header schema for PCAP-NG file ``if_hardware`` options."""
797
+
798
+ #: Hardware information.
799
+ hardware: 'str' = StringField(length=lambda pkt: pkt['length'], encoding='utf-8')
800
+ #: Padding.
801
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
802
+
803
+ if TYPE_CHECKING:
804
+ def __init__(self, type: 'Enum_OptionType', length: 'int', hardware: 'str') -> 'None': ...
805
+
806
+
807
+ @schema_final
808
+ class IF_TxSpeedOption(_IF_Option, code=Enum_OptionType.if_txspeed):
809
+ """Header schema for PCAP-NG file ``if_txspeed`` options."""
810
+
811
+ #: Interface transmit speed, in bits per second.
812
+ tx_speed: 'int' = UInt64Field(callback=byteorder_callback)
813
+ #: Padding.
814
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
815
+
816
+ if TYPE_CHECKING:
817
+ def __init__(self, type: 'Enum_OptionType', length: 'int', tx_speed: 'int') -> 'None': ...
818
+
819
+
820
+ @schema_final
821
+ class IF_RxSpeedOption(_IF_Option, code=Enum_OptionType.if_rxspeed):
822
+ """Header schema for PCAP-NG file ``if_rxspeed`` options."""
823
+
824
+ #: Interface receive speed, in bits per second.
825
+ rx_speed: 'int' = UInt64Field(callback=byteorder_callback)
826
+ #: Padding.
827
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
828
+
829
+ if TYPE_CHECKING:
830
+ def __init__(self, type: 'Enum_OptionType', length: 'int', rx_speed: 'int') -> 'None': ...
831
+
832
+
833
+ @schema_final
834
+ class InterfaceDescriptionBlock(BlockType, code=Enum_BlockType.Interface_Description_Block):
835
+ """Header schema for PCAP-NG Interface Description Block (IDB)."""
836
+
837
+ #: Block total length.
838
+ length: 'int' = UInt32Field(callback=byteorder_callback)
839
+ #: Link type.
840
+ linktype: 'Enum_LinkType' = EnumField(length=2, namespace=Enum_LinkType, callback=byteorder_callback)
841
+ #: Reserved.
842
+ reserved: 'bytes' = PaddingField(length=2)
843
+ #: Snap length.
844
+ snaplen: 'int' = UInt32Field(default=0, callback=byteorder_callback)
845
+ #: Options.
846
+ options: 'list[Option]' = OptionField(
847
+ length=lambda pkt: pkt['length'] - 20,
848
+ base_schema=_IF_Option,
849
+ type_name='type',
850
+ registry=Option.registry['if'],
851
+ eool=Enum_OptionType.opt_endofopt,
852
+ )
853
+ #: Padding.
854
+ padding: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
855
+ #: Block total length.
856
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
857
+
858
+ if TYPE_CHECKING:
859
+ def __init__(self, length: 'int', linktype: 'int', snaplen: 'int',
860
+ options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
861
+
862
+
863
+ class _EPB_Option(Option, namespace='epb'):
864
+ """Header schema for ``epb_*`` options."""
865
+
866
+ #: Option type.
867
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='epb', callback=byteorder_callback)
868
+ #: Option data length.
869
+ length: 'int' = UInt16Field(callback=byteorder_callback)
870
+
871
+
872
+ @schema_final
873
+ class EPB_FlagsOption(_EPB_Option, code=Enum_OptionType.epb_flags):
874
+ """Header schema for PCAP-NG ``epb_flags`` options."""
875
+
876
+ #: Flags.
877
+ flags: 'EPBFlags' = BitField(length=4, namespace={
878
+ 'direction': (0, 2),
879
+ 'reception': (2, 3),
880
+ 'fcs_len': (5, 4),
881
+ 'crc_error': (24, 1),
882
+ 'too_long': (25, 1),
883
+ 'too_short': (26, 1),
884
+ 'gap_error': (27, 1),
885
+ 'unaligned_error': (28, 1),
886
+ 'delimiter_error': (29, 1),
887
+ 'preamble_error': (30, 1),
888
+ 'symbol_error': (31, 1),
889
+ })
890
+ #: Padding.
891
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
892
+
893
+ if TYPE_CHECKING:
894
+ def __init__(self, type: 'Enum_OptionType', length: 'int', flags: 'EPBFlags') -> 'None': ...
895
+
896
+
897
+ @schema_final
898
+ class EPB_HashOption(_EPB_Option, code=Enum_OptionType.epb_hash):
899
+ """Header schema for PCAP-NG ``epb_hash`` options."""
900
+
901
+ #: Hash algorithm.
902
+ func: 'Enum_HashAlgorithm' = EnumField(length=1, namespace=Enum_HashAlgorithm, callback=byteorder_callback)
903
+ #: Hash value.
904
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 1)
905
+ #: Padding.
906
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
907
+
908
+ if TYPE_CHECKING:
909
+ def __init__(self, type: 'Enum_OptionType', length: 'int', func: 'Enum_HashAlgorithm', data: 'bytes') -> 'None': ...
910
+
911
+
912
+ @schema_final
913
+ class EPB_DropCountOption(_EPB_Option, code=Enum_OptionType.epb_dropcount):
914
+ """Header schema for PCAP-NG ``epb_dropcount`` options."""
915
+
916
+ #: Number of packets dropped by the interface.
917
+ drop_count: 'int' = UInt64Field(callback=byteorder_callback)
918
+ #: Padding.
919
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
920
+
921
+ if TYPE_CHECKING:
922
+ def __init__(self, type: 'Enum_OptionType', length: 'int', drop_count: 'int') -> 'None': ...
923
+
924
+
925
+ @schema_final
926
+ class EPB_PacketIDOption(_EPB_Option, code=Enum_OptionType.epb_packetid):
927
+ """Header schema for PCAP-NG ``epb_packetid`` options."""
928
+
929
+ #: Packet ID.
930
+ packet_id: 'int' = UInt64Field(callback=byteorder_callback)
931
+ #: Padding.
932
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
933
+
934
+ if TYPE_CHECKING:
935
+ def __init__(self, type: 'Enum_OptionType', length: 'int', packet_id: 'int') -> 'None': ...
936
+
937
+
938
+ @schema_final
939
+ class EPB_QueueOption(_EPB_Option, code=Enum_OptionType.epb_queue):
940
+ """Header schema for PCAP-NG ``epb_queue`` options."""
941
+
942
+ #: Queue ID.
943
+ queue_id: 'int' = UInt32Field(callback=byteorder_callback)
944
+ #: Padding.
945
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
946
+
947
+ if TYPE_CHECKING:
948
+ def __init__(self, type: 'Enum_OptionType', length: 'int', queue_id: 'int') -> 'None': ...
949
+
950
+
951
+ @schema_final
952
+ class EPB_VerdictOption(_EPB_Option, code=Enum_OptionType.epb_verdict):
953
+ """Header schema for PCAP-NG ``epb_verdict`` options."""
954
+
955
+ #: Verdict type.
956
+ verdict: 'Enum_VerdictType' = EnumField(length=1, namespace=Enum_VerdictType, callback=byteorder_callback)
957
+ #: Verdict value.
958
+ value: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 1)
959
+ #: Padding.
960
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
961
+
962
+ if TYPE_CHECKING:
963
+ def __init__(self, type: 'Enum_OptionType', length: 'int', verdict: 'Enum_VerdictType', value: 'bytes') -> 'None': ...
964
+
965
+
966
+ @schema_final
967
+ class EnhancedPacketBlock(BlockType, code=Enum_BlockType.Enhanced_Packet_Block):
968
+ """Header schema for PCAP-NG Enhanced Packet Block (EPB)."""
969
+
970
+ __payload__ = 'packet_data'
971
+
972
+ #: Block total length.
973
+ length: 'int' = UInt32Field(callback=byteorder_callback)
974
+ #: Interface ID.
975
+ interface_id: 'int' = UInt32Field(callback=byteorder_callback)
976
+ #: Higher 32-bit of timestamp (in seconds).
977
+ timestamp_high: 'int' = UInt32Field(callback=byteorder_callback)
978
+ #: Lower 32-bit of timestamp (in seconds).
979
+ timestamp_low: 'int' = UInt32Field(callback=byteorder_callback)
980
+ #: Captured packet length.
981
+ captured_len: 'int' = UInt32Field(callback=byteorder_callback)
982
+ #: Original packet length.
983
+ original_len: 'int' = UInt32Field(callback=byteorder_callback)
984
+ #: Packet data.
985
+ packet_data: 'bytes' = PayloadField(length=lambda pkt: pkt['captured_len'])
986
+ #: Padding.
987
+ padding_data: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['captured_len'] % 4) % 4)
988
+ #: Options.
989
+ options: 'list[Option]' = OptionField(
990
+ length=lambda pkt: pkt['length'] - 32 - pkt['captured_len'] - len(pkt['padding_data']),
991
+ base_schema=_EPB_Option,
992
+ type_name='type',
993
+ registry=Option.registry['epb'],
994
+ eool=Enum_OptionType.opt_endofopt,
995
+ )
996
+ #: Padding.
997
+ padding_opts: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
998
+ #: Block total length.
999
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1000
+
1001
+ if TYPE_CHECKING:
1002
+ def __init__(self, length: 'int', interface_id: 'int', timestamp_high: 'int',
1003
+ timestamp_low: 'int', captured_len: 'int', original_len: 'int',
1004
+ packet_data: 'bytes | Protocol | Schema',
1005
+ options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
1006
+
1007
+
1008
+ @schema_final
1009
+ class SimplePacketBlock(BlockType, code=Enum_BlockType.Simple_Packet_Block):
1010
+ """Header schema for PCAP-NG Simple Packet Block (SPB)."""
1011
+
1012
+ __payload__ = 'packet_data'
1013
+
1014
+ #: Block total length.
1015
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1016
+ #: Original packet length.
1017
+ original_len: 'int' = UInt32Field(callback=byteorder_callback)
1018
+ #: Packet data.
1019
+ packet_data: 'bytes' = PayloadField(length=lambda pkt: min(pkt.get('snaplen', 0xFFFFFFFFFFFFFFFF),
1020
+ pkt['original_len']))
1021
+ #: Padding.
1022
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - len(pkt['packet_data']) % 4) % 4)
1023
+ #: Block total length.
1024
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1025
+
1026
+ if TYPE_CHECKING:
1027
+ def __init__(self, length: 'int', original_len: 'int',
1028
+ packet_data: 'bytes | Protocol | Schema',
1029
+ length2: 'int') -> 'None': ...
1030
+
1031
+
1032
+ class NameResolutionRecord(EnumSchema[Enum_RecordType]):
1033
+ """Header schema for PCAP-NG NRB records."""
1034
+
1035
+ __default__ = lambda: UnknownRecord
1036
+
1037
+ #: Record type.
1038
+ type: 'Enum_RecordType' = EnumField(length=2, namespace=Enum_RecordType, callback=byteorder_callback)
1039
+ #: Record value length.
1040
+ length: 'int' = UInt16Field(callback=byteorder_callback)
1041
+
1042
+
1043
+ @schema_final
1044
+ class UnknownRecord(NameResolutionRecord):
1045
+ """Header schema for PCAP-NG NRB unknown records."""
1046
+
1047
+ #: Unknown record data.
1048
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['length'])
1049
+ #: Padding.
1050
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
1051
+
1052
+ if TYPE_CHECKING:
1053
+ def __init__(self, type: 'Enum_RecordType', length: 'int', data: 'bytes') -> 'None': ...
1054
+
1055
+
1056
+ @schema_final
1057
+ class EndRecord(NameResolutionRecord, code=Enum_RecordType.nrb_record_end):
1058
+ """Header schema for PCAP-NG ``nrb_record_end`` records."""
1059
+
1060
+ if TYPE_CHECKING:
1061
+ def __init__(self, type: 'Enum_RecordType', length: 'int') -> 'None': ...
1062
+
1063
+
1064
+ @schema_final
1065
+ class IPv4Record(NameResolutionRecord, code=Enum_RecordType.nrb_record_ipv4):
1066
+ """Header schema for PCAP-NG NRB ``nrb_record_ipv4`` records."""
1067
+
1068
+ #: IPv4 address.
1069
+ ip: 'IPv4Address' = IPv4AddressField()
1070
+ #: Name resolution data.
1071
+ resol: 'str' = StringField(length=lambda pkt: pkt['length'] - 4)
1072
+ #: Padding.
1073
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
1074
+
1075
+ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
1076
+ """Revise ``schema`` data after unpacking process.
1077
+
1078
+ Args:
1079
+ packet: Unpacked data.
1080
+
1081
+ Returns:
1082
+ Revised schema.
1083
+
1084
+ """
1085
+ self.names = self.resol.rstrip('\x00').split('\x00')
1086
+ return self
1087
+
1088
+ if TYPE_CHECKING:
1089
+ #: Name resolution records.
1090
+ names: 'list[str]'
1091
+
1092
+ def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv4Address | str | bytes | int', resol: 'str') -> 'None': ...
1093
+
1094
+
1095
+ @schema_final
1096
+ class IPv6Record(NameResolutionRecord, code=Enum_RecordType.nrb_record_ipv6):
1097
+ """Header schema for PCAP-NG NRB ``nrb_record_ipv4`` records."""
1098
+
1099
+ #: IPv4 address.
1100
+ ip: 'IPv6Address' = IPv6AddressField()
1101
+ #: Name resolution data.
1102
+ resol: 'str' = StringField(length=lambda pkt: pkt['length'] - 4)
1103
+ #: Padding.
1104
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
1105
+
1106
+ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
1107
+ """Revise ``schema`` data after unpacking process.
1108
+
1109
+ Args:
1110
+ packet: Unpacked data.
1111
+
1112
+ Returns:
1113
+ Revised schema.
1114
+
1115
+ """
1116
+ self.names = self.resol.rstrip('\x00').split('\x00')
1117
+ return self
1118
+
1119
+ if TYPE_CHECKING:
1120
+ #: Name resolution records.
1121
+ names: 'list[str]'
1122
+
1123
+ def __init__(self, type: 'Enum_RecordType', length: 'int', ip: 'IPv6Address | str | bytes | int', resol: 'str') -> 'None': ...
1124
+
1125
+
1126
+ class _NS_Option(Option, namespace='ns'):
1127
+ """Header schema for ``ns_*`` options."""
1128
+
1129
+ #: Option type.
1130
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='ns', callback=byteorder_callback)
1131
+ #: Option data length.
1132
+ length: 'int' = UInt16Field(callback=byteorder_callback)
1133
+
1134
+
1135
+ @schema_final
1136
+ class NS_DNSNameOption(_NS_Option, code=Enum_OptionType.ns_dnsname):
1137
+ """Header schema for PCAP-NG ``ns_dnsname`` option."""
1138
+
1139
+ #: DNS name.
1140
+ name: 'str' = StringField(length=lambda pkt: pkt['length'])
1141
+
1142
+ if TYPE_CHECKING:
1143
+ def __init__(self, type: 'Enum_OptionType', length: 'int', name: 'str') -> 'None': ...
1144
+
1145
+
1146
+ @schema_final
1147
+ class NS_DNSIP4AddrOption(_NS_Option, code=Enum_OptionType.ns_dnsIP4addr):
1148
+ """Header schema for PCAP-NG ``ns_dnsIP4addr`` option."""
1149
+
1150
+ #: IPv4 address.
1151
+ ip: 'IPv4Address' = IPv4AddressField()
1152
+
1153
+ if TYPE_CHECKING:
1154
+ def __init__(self, type: 'Enum_OptionType', length: 'int', ip: 'IPv4Address | str | bytes | int') -> 'None': ...
1155
+
1156
+
1157
+ @schema_final
1158
+ class NS_DNSIP6AddrOption(_NS_Option, code=Enum_OptionType.ns_dnsIP6addr):
1159
+ """Header schema for PCAP-NG ``ns_dnsIP6addr`` option."""
1160
+
1161
+ #: IPv6 address.
1162
+ ip: 'IPv6Address' = IPv6AddressField()
1163
+
1164
+ if TYPE_CHECKING:
1165
+ def __init__(self, type: 'Enum_OptionType', length: 'int', ip: 'IPv6Address | bytes | str | int') -> 'None': ...
1166
+
1167
+
1168
+ @schema_final
1169
+ class NameResolutionBlock(BlockType, code=Enum_BlockType.Name_Resolution_Block):
1170
+ """Header schema for PCAP-NG Name Resolution Block (NRB)."""
1171
+
1172
+ #: Record total length.
1173
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1174
+ #: Name resolution records.
1175
+ records: 'list[NameResolutionRecord]' = OptionField(
1176
+ length=lambda pkt: pkt['length'] - 12,
1177
+ base_schema=NameResolutionRecord,
1178
+ type_name='type',
1179
+ registry=NameResolutionRecord.registry,
1180
+ eool=Enum_RecordType.nrb_record_end,
1181
+ )
1182
+ #: Options.
1183
+ options: 'list[Option]' = OptionField(
1184
+ length=lambda pkt: pkt['__option_padding__'] - 4 if pkt['__option_padding__'] else 0,
1185
+ base_schema=_NS_Option,
1186
+ type_name='type',
1187
+ registry=Option.registry['ns'],
1188
+ eool=Enum_OptionType.opt_endofopt,
1189
+ )
1190
+ #: Padding.
1191
+ padding: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
1192
+ #: Block total length.
1193
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1194
+
1195
+ def post_process(self, packet: 'dict[str, Any]') -> 'Self':
1196
+ """Revise ``schema`` data after unpacking process.
1197
+
1198
+ Args:
1199
+ packet: Unpacked data.
1200
+
1201
+ Returns:
1202
+ Revised schema.
1203
+
1204
+ """
1205
+ self = cast('Self', super().post_process(packet))
1206
+
1207
+ mapping = MultiDict() # type: MultiDict[IPv4Address | IPv6Address, str]
1208
+ reverse_mapping = MultiDict() # type: MultiDict[str, IPv4Address | IPv6Address]
1209
+
1210
+ for record in self.records:
1211
+ if isinstance(record, (IPv4Record, IPv6Record)):
1212
+ for name in record.names:
1213
+ mapping.add(record.ip, name)
1214
+ reverse_mapping.add(name, record.ip)
1215
+
1216
+ self.mapping = mapping
1217
+ self.reverse_mapping = reverse_mapping
1218
+ return self
1219
+
1220
+ if TYPE_CHECKING:
1221
+ #: Name resolution mapping (IP address -> name).
1222
+ mapping: 'MultiDict[IPv4Address | IPv6Address, str]'
1223
+ #: Name resolution mapping (name -> IP address).
1224
+ reverse_mapping: 'MultiDict[str, IPv4Address | IPv6Address]'
1225
+
1226
+ def __init__(self, length: 'int',
1227
+ records: 'list[NameResolutionRecord | bytes] | bytes',
1228
+ options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
1229
+
1230
+
1231
+ class _ISB_Option(Option, namespace='isb'):
1232
+ """Header schema for ``isb_*`` options."""
1233
+
1234
+ #: Option type.
1235
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='isb', callback=byteorder_callback)
1236
+ #: Option data length.
1237
+ length: 'int' = UInt16Field(callback=byteorder_callback)
1238
+
1239
+
1240
+ @schema_final
1241
+ class ISB_StartTimeOption(_ISB_Option, code=Enum_OptionType.isb_starttime):
1242
+ """Header schema for PCAP-NG ``isb_starttime`` option."""
1243
+
1244
+ #: Timestamp (higher 32 bits).
1245
+ timestamp_high: 'int' = UInt32Field(callback=byteorder_callback)
1246
+ #: Timestamp (lower 32 bits).
1247
+ timestamp_low: 'int' = UInt32Field(callback=byteorder_callback)
1248
+
1249
+ if TYPE_CHECKING:
1250
+ def __init__(self, type: 'Enum_OptionType', length: 'int', timestamp_high: 'int', timestamp_low: 'int') -> 'None': ...
1251
+
1252
+
1253
+ @schema_final
1254
+ class ISB_EndTimeOption(_ISB_Option, code=Enum_OptionType.isb_endtime):
1255
+ """Header schema for PCAP-NG ``isb_endtime`` option."""
1256
+
1257
+ #: Timestamp (higher 32 bits).
1258
+ timestamp_high: 'int' = UInt32Field(callback=byteorder_callback)
1259
+ #: Timestamp (lower 32 bits).
1260
+ timestamp_low: 'int' = UInt32Field(callback=byteorder_callback)
1261
+
1262
+ if TYPE_CHECKING:
1263
+ def __init__(self, type: 'Enum_OptionType', length: 'int', timestamp_high: 'int', timestamp_low: 'int') -> 'None': ...
1264
+
1265
+
1266
+ @schema_final
1267
+ class ISB_IFRecvOption(_ISB_Option, code=Enum_OptionType.isb_ifrecv):
1268
+ """Header schema for PCAP-NG ``isb_ifrecv`` option."""
1269
+
1270
+ #: Number of packets received.
1271
+ packets: 'int' = UInt64Field(callback=byteorder_callback)
1272
+
1273
+ if TYPE_CHECKING:
1274
+ def __init__(self, type: 'Enum_OptionType', length: 'int', packets: 'int') -> 'None': ...
1275
+
1276
+
1277
+ @schema_final
1278
+ class ISB_IFDropOption(_ISB_Option, code=Enum_OptionType.isb_ifdrop):
1279
+ """Header schema for PCAP-NG ``isb_ifdrop`` option."""
1280
+
1281
+ #: Number of packets dropped.
1282
+ packets: 'int' = UInt64Field(callback=byteorder_callback)
1283
+
1284
+ if TYPE_CHECKING:
1285
+ def __init__(self, type: 'Enum_OptionType', length: 'int', packets: 'int') -> 'None': ...
1286
+
1287
+
1288
+ @schema_final
1289
+ class ISB_FilterAcceptOption(_ISB_Option, code=Enum_OptionType.isb_filteraccept):
1290
+ """Header schema for PCAP-NG ``isb_filteraccept`` option."""
1291
+
1292
+ #: Number of packets accepted by filter.
1293
+ packets: 'int' = UInt64Field(callback=byteorder_callback)
1294
+
1295
+ if TYPE_CHECKING:
1296
+ def __init__(self, type: 'Enum_OptionType', length: 'int', packets: 'int') -> 'None': ...
1297
+
1298
+
1299
+ @schema_final
1300
+ class ISB_OSDropOption(_ISB_Option, code=Enum_OptionType.isb_osdrop):
1301
+ """Header schema for PCAP-NG ``isb_osdrop`` option."""
1302
+
1303
+ #: Number of packets dropped by OS.
1304
+ packets: 'int' = UInt64Field(callback=byteorder_callback)
1305
+
1306
+ if TYPE_CHECKING:
1307
+ def __init__(self, type: 'Enum_OptionType', length: 'int', packets: 'int') -> 'None': ...
1308
+
1309
+
1310
+ @schema_final
1311
+ class ISB_UsrDelivOption(_ISB_Option, code=Enum_OptionType.isb_usrdeliv):
1312
+ """Header schema for PCAP-NG ``isb_usrdeliv`` option."""
1313
+
1314
+ #: Number of packets delivered to user.
1315
+ packets: 'int' = UInt64Field(callback=byteorder_callback)
1316
+
1317
+ if TYPE_CHECKING:
1318
+ def __init__(self, type: 'Enum_OptionType', length: 'int', packets: 'int') -> 'None': ...
1319
+
1320
+
1321
+ @schema_final
1322
+ class InterfaceStatisticsBlock(BlockType):
1323
+ """Header schema for PCAP-NG Interface Statistics Block (ISB)."""
1324
+
1325
+ #: Block total length.
1326
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1327
+ #: Interface ID.
1328
+ interface_id: 'int' = UInt32Field(callback=byteorder_callback)
1329
+ #: Timestamp (higher 32 bits).
1330
+ timestamp_high: 'int' = UInt32Field(callback=byteorder_callback)
1331
+ #: Timestamp (lower 32 bits).
1332
+ timestamp_low: 'int' = UInt32Field(callback=byteorder_callback)
1333
+ #: Options.
1334
+ options: 'list[Option]' = OptionField(
1335
+ length=lambda pkt: pkt['length'] - 20,
1336
+ base_schema=_ISB_Option,
1337
+ type_name='type',
1338
+ registry=Option.registry['isb'],
1339
+ eool=Enum_OptionType.opt_endofopt,
1340
+ )
1341
+ #: Padding.
1342
+ padding: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
1343
+ #: Block total length.
1344
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1345
+
1346
+ if TYPE_CHECKING:
1347
+ def __init__(self, length: 'int', interface_id: 'int',
1348
+ timestamp_high: 'int', timestamp_low: 'int',
1349
+ options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
1350
+
1351
+
1352
+ @schema_final
1353
+ class SystemdJournalExportBlock(BlockType, code=Enum_BlockType.systemd_Journal_Export_Block):
1354
+ """Header schema for PCAP-NG :manpage:`systemd(1)` Journal Export Block."""
1355
+
1356
+ #: Block total length.
1357
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1358
+ #: Journal entry.
1359
+ entry: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 12)
1360
+ #: Block total length.
1361
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1362
+
1363
+ def post_process(self, packet: 'dict[str, Any]') -> 'Self':
1364
+ """Revise ``schema`` data after unpacking process.
1365
+
1366
+ Args:
1367
+ packet: Unpacked data.
1368
+
1369
+ Returns:
1370
+ Revised schema.
1371
+
1372
+ """
1373
+ self = cast('Self', super().post_process(packet))
1374
+
1375
+ data = [] # type: list[OrderedMultiDict[str, str | bytes]]
1376
+ for entry_buffer in self.entry.split(b'\n\n'):
1377
+ entry = OrderedMultiDict() # type: OrderedMultiDict[str, str | bytes]
1378
+
1379
+ entry_data = io.BytesIO(entry_buffer)
1380
+ while True:
1381
+ line = entry_data.readline().strip()
1382
+ if not line:
1383
+ break
1384
+
1385
+ line_split = line.split(b'=', maxsplit=1)
1386
+ if len(line_split) == 2:
1387
+ key, value = line_split
1388
+ entry.add(key.decode('utf-8'), value.decode('utf-8'))
1389
+ else:
1390
+ length = struct.unpack('<Q', entry_data.read(4))[0] # type: int
1391
+ entry.add(line.decode('utf-8'), entry_data.read(length))
1392
+ entry_data.read() # Skip trailing newline.
1393
+
1394
+ data.append(entry)
1395
+ self.data = data
1396
+ return self
1397
+
1398
+ if TYPE_CHECKING:
1399
+ #: Journal entry (decoded).
1400
+ data: 'list[OrderedMultiDict[str, str | bytes]]'
1401
+
1402
+ def __init__(self, length: 'int', entry: 'bytes', length2: 'int') -> 'None': ...
1403
+
1404
+
1405
+ class DSBSecrets(EnumSchema[Enum_SecretsType]):
1406
+ """Header schema for DSB secrets data."""
1407
+
1408
+ __default__ = lambda: UnknownSecrets
1409
+
1410
+
1411
+ @schema_final
1412
+ class UnknownSecrets(DSBSecrets):
1413
+ """Header schema for unknown DSB secrets data."""
1414
+
1415
+ #: Secrets data.
1416
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['__length__'])
1417
+
1418
+ if TYPE_CHECKING:
1419
+ def __init__(self, data: 'bytes') -> 'None': ...
1420
+
1421
+
1422
+ @schema_final
1423
+ class TLSKeyLog(DSBSecrets, code=Enum_SecretsType.TLS_Key_Log):
1424
+ """Header schema for TLS Key Log secrets data."""
1425
+
1426
+ #: TLS key log data.
1427
+ data: 'str' = StringField(length=lambda pkt: pkt['__length__'], encoding='ascii')
1428
+
1429
+ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
1430
+ """Revise ``schema`` data after unpacking process.
1431
+
1432
+ Args:
1433
+ packet: Unpacked data.
1434
+
1435
+ Returns:
1436
+ Revised schema.
1437
+
1438
+ """
1439
+ from pcapkit.protocols.misc.pcapng import TLSKeyLabel
1440
+
1441
+ entries = collections.defaultdict(OrderedMultiDict) # type: dict[TLSKeyLabel, OrderedMultiDict[bytes, bytes]]
1442
+ for line in self.data.splitlines():
1443
+ if not line or line.startswith('#'):
1444
+ continue
1445
+
1446
+ label, random, secret = line.strip().split()
1447
+ label_enum = TLSKeyLabel(label.upper())
1448
+ entries[label_enum].add(bytes.fromhex(random),
1449
+ bytes.fromhex(secret))
1450
+
1451
+ self.entries = entries
1452
+ return self
1453
+
1454
+ if TYPE_CHECKING:
1455
+ #: TLS Key Log entries.
1456
+ entries: 'dict[TLSKeyLabel, OrderedMultiDict[bytes, bytes]]'
1457
+
1458
+ def __init__(self, data: 'str') -> 'None': ...
1459
+
1460
+
1461
+ @schema_final
1462
+ class WireGuardKeyLog(DSBSecrets, code=Enum_SecretsType.WireGuard_Key_Log):
1463
+ """Header schema for WireGuard Key Log secrets data."""
1464
+
1465
+ #: WireGuard key log data.
1466
+ data: 'str' = StringField(length=lambda pkt: pkt['__length__'], encoding='ascii')
1467
+
1468
+ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
1469
+ """Revise ``schema`` data after unpacking process.
1470
+
1471
+ Args:
1472
+ packet: Unpacked data.
1473
+
1474
+ Returns:
1475
+ Revised schema.
1476
+
1477
+ """
1478
+ from pcapkit.protocols.misc.pcapng import WireGuardKeyLabel
1479
+
1480
+ entries = OrderedMultiDict() # type: OrderedMultiDict[WireGuardKeyLabel, bytes]
1481
+ for line in self.data.splitlines():
1482
+ if not line or line.startswith('#'):
1483
+ continue
1484
+
1485
+ label, op, secret = line.strip().split()
1486
+ if op != '=':
1487
+ raise FieldValueError('invalid WireGuard key log format: {line!r}')
1488
+ label_enum = WireGuardKeyLabel(label.upper())
1489
+ entries.add(label_enum, base64.b64decode(secret))
1490
+
1491
+ self.entries = entries
1492
+ return self
1493
+
1494
+ if TYPE_CHECKING:
1495
+ #: WireGuard Key Log entries.
1496
+ entries: 'OrderedMultiDict[WireGuardKeyLabel, bytes]'
1497
+
1498
+ def __init__(self, data: 'str') -> 'None': ...
1499
+
1500
+
1501
+ @schema_final
1502
+ class ZigBeeNWKKey(DSBSecrets, code=Enum_SecretsType.ZigBee_NWK_Key):
1503
+ """Header schema for ZigBee NWK Key and ZigBee PANID secrets data."""
1504
+
1505
+ #: AES-128 NKW key.
1506
+ key: 'bytes' = BytesField(length=16)
1507
+ #: ZigBee PANID.
1508
+ panid: 'int' = UInt16Field(byteorder='little')
1509
+ #: Padding.
1510
+ padding: 'bytes' = BytesField(length=2)
1511
+
1512
+ if TYPE_CHECKING:
1513
+ def __init__(self, key: 'bytes', panid: 'int') -> 'None': ...
1514
+
1515
+
1516
+ @schema_final
1517
+ class ZigBeeAPSKey(DSBSecrets, code=Enum_SecretsType.ZigBee_APS_Key):
1518
+ """Header schema for ZigBee APS Key secrets data."""
1519
+
1520
+ #: AES-128 APS key.
1521
+ key: 'bytes' = BytesField(length=16)
1522
+ #: ZigBee PANID.
1523
+ panid: 'int' = UInt16Field(byteorder='little')
1524
+ #: Low node short address.
1525
+ addr_low: 'int' = UInt16Field(byteorder='little')
1526
+ #: High node short address.
1527
+ addr_high: 'int' = UInt16Field(byteorder='little')
1528
+ #: Padding.
1529
+ padding: 'bytes' = BytesField(length=2)
1530
+
1531
+ if TYPE_CHECKING:
1532
+ def __init__(self, key: 'bytes', panid: 'int', addr_low: 'int', addr_high: 'int') -> 'None': ...
1533
+
1534
+
1535
+ class _DSB_Option(Option, namespace='dsb'):
1536
+ """Header schema for ``dsb_*`` options."""
1537
+
1538
+ #: Option type.
1539
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='dsb', callback=byteorder_callback)
1540
+ #: Option data length.
1541
+ length: 'int' = UInt16Field(callback=byteorder_callback)
1542
+
1543
+
1544
+ @schema_final
1545
+ class DecryptionSecretsBlock(BlockType, code=Enum_BlockType.Decryption_Secrets_Block):
1546
+ """Header schema for PCAP-NG Decryption Secrets Block (DSB)."""
1547
+
1548
+ #: Block total length.
1549
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1550
+ #: Secrets type.
1551
+ secrets_type: 'Enum_SecretsType' = EnumField(length=4, namespace=Enum_SecretsType, callback=byteorder_callback)
1552
+ #: Secrets length.
1553
+ secrets_length: 'int' = UInt32Field(callback=byteorder_callback)
1554
+ #: Secrets data.
1555
+ secrets_data: 'DSBSecrets' = SwitchField(
1556
+ selector=dsb_secrets_selector,
1557
+ )
1558
+ #: Padding.
1559
+ padding_data: 'bytes' = BytesField(length=lambda pkt: (4 - pkt['secrets_length'] % 4) % 4)
1560
+ #: Options.
1561
+ options: 'list[Option]' = OptionField(
1562
+ length=lambda pkt: pkt['length'] - 20 - pkt['secrets_length'] - len(pkt['padding_data']),
1563
+ base_schema=_DSB_Option,
1564
+ type_name='type',
1565
+ registry=Option.registry['dsb'],
1566
+ eool=Enum_OptionType.opt_endofopt,
1567
+ )
1568
+ #: Padding.
1569
+ padding_opts: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
1570
+ #: Block total length.
1571
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1572
+
1573
+ if TYPE_CHECKING:
1574
+ def __init__(self, length: 'int', secrets_type: 'Enum_SecretsType',
1575
+ secrets_length: 'int', secrets_data: 'DSBSecrets | bytes',
1576
+ options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...
1577
+
1578
+
1579
+ @schema_final
1580
+ class CustomBlock(BlockType, code=[Enum_BlockType.Custom_Block_that_rewriters_can_copy_into_new_files,
1581
+ Enum_BlockType.Custom_Block_that_rewriters_should_not_copy_into_new_files]):
1582
+ """Header schema for PCAP-NG Custom Block (CB)."""
1583
+
1584
+ #: Block total length.
1585
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1586
+ #: Private enterprise number.
1587
+ pen: 'int' = UInt32Field(callback=byteorder_callback)
1588
+ #: Custom data.
1589
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 16)
1590
+ #: Padding.
1591
+ padding: 'bytes' = BytesField(length=lambda pkt: (4 - pkt['data'] % 4) % 4)
1592
+ #: Block total length.
1593
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1594
+
1595
+ if TYPE_CHECKING:
1596
+ def __init__(self, length: 'int', pen: 'int', data: 'bytes', length2: 'int') -> 'None': ...
1597
+
1598
+
1599
+ class _PACK_Option(Option, namespace='pack'):
1600
+ """Header schema for ``pack_*`` options."""
1601
+
1602
+ #: Option type.
1603
+ type: 'Enum_OptionType' = OptionEnumField(length=2, namespace='pack', callback=byteorder_callback)
1604
+ #: Option data length.
1605
+ length: 'int' = UInt16Field(callback=byteorder_callback)
1606
+
1607
+
1608
+ @schema_final
1609
+ class PACK_FlagsOption(_PACK_Option, code=Enum_OptionType.pack_flags):
1610
+ """Header schema for PCAP-NG ``pack_flags`` options."""
1611
+
1612
+ #: Flags.
1613
+ flags: 'PACKFlags' = BitField(length=4, namespace={
1614
+ 'direction': (0, 2),
1615
+ 'reception': (2, 3),
1616
+ 'fcs_len': (5, 4),
1617
+ 'crc_error': (24, 1),
1618
+ 'too_long': (25, 1),
1619
+ 'too_short': (26, 1),
1620
+ 'gap_error': (27, 1),
1621
+ 'unaligned_error': (28, 1),
1622
+ 'delimiter_error': (29, 1),
1623
+ 'preamble_error': (30, 1),
1624
+ 'symbol_error': (31, 1),
1625
+ })
1626
+ #: Padding.
1627
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
1628
+
1629
+ if TYPE_CHECKING:
1630
+ def __init__(self, type: 'Enum_OptionType', length: 'int', flags: 'EPBFlags') -> 'None': ...
1631
+
1632
+
1633
+ @schema_final
1634
+ class PACK_HashOption(_PACK_Option, code=Enum_OptionType.pack_hash):
1635
+ """Header schema for PCAP-NG ``pack_hash`` options."""
1636
+
1637
+ #: Hash algorithm.
1638
+ func: 'Enum_HashAlgorithm' = EnumField(length=1, namespace=Enum_HashAlgorithm, callback=byteorder_callback)
1639
+ #: Hash value.
1640
+ data: 'bytes' = BytesField(length=lambda pkt: pkt['length'] - 1)
1641
+ #: Padding.
1642
+ padding: 'bytes' = PaddingField(length=lambda pkt: (4 - pkt['length'] % 4) % 4)
1643
+
1644
+ if TYPE_CHECKING:
1645
+ def __init__(self, type: 'Enum_OptionType', length: 'int', func: 'Enum_HashAlgorithm', data: 'bytes') -> 'None': ...
1646
+
1647
+
1648
+ @schema_final
1649
+ class PacketBlock(BlockType, code=Enum_BlockType.Packet_Block):
1650
+ """Header schema for PCAP-NG Packet Block (obsolete)."""
1651
+
1652
+ __payload__ = 'packet_data'
1653
+
1654
+ #: Block total length.
1655
+ length: 'int' = UInt32Field(callback=byteorder_callback)
1656
+ #: Interface ID.
1657
+ interface_id: 'int' = UInt32Field(callback=byteorder_callback)
1658
+ #: Drops count.
1659
+ drop_count: 'int' = UInt32Field(callback=byteorder_callback, default=0xFFFF)
1660
+ #: Timestamp (high).
1661
+ timestamp_high: 'int' = UInt32Field(callback=byteorder_callback)
1662
+ #: Timestamp (low).
1663
+ timestamp_low: 'int' = UInt32Field(callback=byteorder_callback)
1664
+ #: Captured packet length.
1665
+ captured_length: 'int' = UInt32Field(callback=byteorder_callback)
1666
+ #: Original packet length.
1667
+ original_length: 'int' = UInt32Field(callback=byteorder_callback)
1668
+ #: Packet data.
1669
+ packet_data: 'bytes' = PayloadField(length=lambda pkt: pkt['captured_length'])
1670
+ #: Padding.
1671
+ padding_data: 'bytes' = BytesField(length=lambda pkt: (4 - pkt['captured_length'] % 4) % 4)
1672
+ #: Options.
1673
+ options: 'list[Option]' = OptionField(
1674
+ length=lambda pkt: pkt['length'] - 32 - pkt['captured_length'] - len(pkt['padding_data']),
1675
+ base_schema=_PACK_Option,
1676
+ type_name='type',
1677
+ registry=Option.registry['pack'],
1678
+ eool=Enum_OptionType.opt_endofopt,
1679
+ )
1680
+ #: Padding.
1681
+ padding_opts: 'bytes' = PaddingField(length=lambda pkt: pkt['__option_padding__'])
1682
+ #: Block total length.
1683
+ length2: 'int' = UInt32Field(callback=byteorder_callback)
1684
+
1685
+ if TYPE_CHECKING:
1686
+ def __init__(self, length: 'int', interface_id: 'int', drop_count: 'int',
1687
+ timestamp_high: 'int', timestamp_low: 'int', captured_length: 'int',
1688
+ original_length: 'int', packet_data: 'bytes | Protocol | Schema',
1689
+ options: 'list[Option | bytes] | bytes', length2: 'int') -> 'None': ...