pypcapkit 1.0.3__cp310-none-any.whl → 1.1.0__cp310-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 (41) hide show
  1. pcapkit/__init__.py +1 -1
  2. pcapkit/const/pcapng/option_type.py +4 -1
  3. pcapkit/const/reg/apptype.py +19019 -19015
  4. pcapkit/corekit/fields/collections.py +14 -14
  5. pcapkit/corekit/fields/field.py +33 -8
  6. pcapkit/corekit/fields/ipaddress.py +0 -1
  7. pcapkit/corekit/fields/misc.py +14 -19
  8. pcapkit/corekit/fields/numbers.py +2 -3
  9. pcapkit/corekit/fields/strings.py +2 -3
  10. pcapkit/corekit/infoclass.py +59 -6
  11. pcapkit/corekit/protochain.py +8 -1
  12. pcapkit/foundation/registry/protocols.py +108 -16
  13. pcapkit/protocols/data/__init__.py +4 -4
  14. pcapkit/protocols/data/internet/__init__.py +4 -4
  15. pcapkit/protocols/data/internet/mh.py +8 -6
  16. pcapkit/protocols/data/transport/__init__.py +4 -4
  17. pcapkit/protocols/data/transport/tcp.py +4 -4
  18. pcapkit/protocols/internet/mh.py +21 -21
  19. pcapkit/protocols/protocol.py +3 -2
  20. pcapkit/protocols/schema/__init__.py +4 -4
  21. pcapkit/protocols/schema/application/httpv2.py +17 -33
  22. pcapkit/protocols/schema/internet/__init__.py +4 -4
  23. pcapkit/protocols/schema/internet/hip.py +62 -111
  24. pcapkit/protocols/schema/internet/hopopt.py +46 -48
  25. pcapkit/protocols/schema/internet/ipv4.py +36 -41
  26. pcapkit/protocols/schema/internet/ipv6_opts.py +48 -52
  27. pcapkit/protocols/schema/internet/ipv6_route.py +12 -21
  28. pcapkit/protocols/schema/internet/mh.py +57 -86
  29. pcapkit/protocols/schema/misc/pcapng.py +182 -193
  30. pcapkit/protocols/schema/schema.py +252 -53
  31. pcapkit/protocols/schema/transport/__init__.py +4 -4
  32. pcapkit/protocols/schema/transport/tcp.py +54 -81
  33. pcapkit/protocols/transport/tcp.py +14 -14
  34. pcapkit/vendor/pcapng/option_type.py +29 -2
  35. pcapkit/vendor/reg/apptype.py +34 -4
  36. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/METADATA +1 -1
  37. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/RECORD +41 -41
  38. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/LICENSE +0 -0
  39. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/WHEEL +0 -0
  40. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/entry_points.txt +0 -0
  41. {pypcapkit-1.0.3.dist-info → pypcapkit-1.1.0.dist-info}/top_level.txt +0 -0
@@ -17,7 +17,7 @@ from pcapkit.corekit.fields.misc import (ConditionalField, ForwardMatchField, Pa
17
17
  from pcapkit.corekit.fields.numbers import (EnumField, NumberField, UInt8Field, UInt16Field,
18
18
  UInt32Field, UInt64Field)
19
19
  from pcapkit.corekit.fields.strings import BitField, BytesField, PaddingField
20
- from pcapkit.protocols.schema.schema import Schema, schema_final
20
+ from pcapkit.protocols.schema.schema import EnumSchema, Schema, schema_final
21
21
  from pcapkit.utilities.exceptions import FieldError
22
22
  from pcapkit.utilities.logging import SPHINX_TYPE_CHECKING
23
23
 
@@ -26,8 +26,8 @@ __all__ = [
26
26
 
27
27
  'Option',
28
28
  'UnassignedOption', 'EndOfOptionList', 'NoOperation', 'MaximumSegmentSize', 'WindowScale',
29
- 'SACKPermitted', 'SACK', 'Echo', 'EchoReply', 'Timestamp', 'PartialOrderConnectionPermitted',
30
- 'PartialOrderConnectionProfile', 'CC', 'CCNew', 'CCEcho', 'AlternateChecksumRequest',
29
+ 'SACKPermitted', 'SACK', 'Echo', 'EchoReply', 'Timestamps', 'PartialOrderConnectionPermitted',
30
+ 'PartialOrderServiceProfile', 'CC', 'CCNew', 'CCEcho', 'AlternateChecksumRequest',
31
31
  'AlternateChecksumData', 'MD5Signature', 'QuickStartResponse', 'UserTimeout',
32
32
  'Authentication', 'FastOpenCookie',
33
33
 
@@ -41,7 +41,7 @@ __all__ = [
41
41
 
42
42
  if TYPE_CHECKING:
43
43
  from ipaddress import IPv4Address, IPv6Address
44
- from typing import Any, Optional
44
+ from typing import Any, DefaultDict, Optional, Type
45
45
 
46
46
  from pcapkit.corekit.fields.field import _Field as Field
47
47
  from pcapkit.protocols.protocol import Protocol
@@ -199,30 +199,18 @@ def mptcp_data_selector(pkt: 'dict[str, Any]') -> 'Field':
199
199
  """
200
200
  subtype = Enum_MPTCPOption.get(pkt['test']['subtype'])
201
201
  pkt['test']['subtype'] = subtype
202
+ schema = MPTCP.registry[subtype]
202
203
 
203
- if subtype == Enum_MPTCPOption.MP_CAPABLE:
204
- return SchemaField(length=pkt['test']['length'], schema=MPTCPCapable)
205
- if subtype == Enum_MPTCPOption.MP_JOIN:
204
+ if subtype == Enum_MPTCPOption.MP_JOIN and schema is MPTCPJoin: # placeholder
206
205
  if pkt['flags']['syn'] == 1 and pkt['flags']['ack'] == 0:
207
- return SchemaField(length=pkt['test']['length'], schema=MPTCPJoinSYN)
208
- if pkt['flags']['syn'] == 1 and pkt['flags']['ack'] == 1:
209
- return SchemaField(length=pkt['test']['length'], schema=MPTCPJoinSYNACK)
210
- if pkt['flags']['syn'] == 0 and pkt['flags']['ack'] == 1:
211
- return SchemaField(length=pkt['test']['length'], schema=MPTCPJoinACK)
212
- raise FieldError(f'TCP: [OptNo {Enum_Option.Multipath_TCP}] {Enum_MPTCPOption.MP_JOIN} invalid flags')
213
- if subtype == Enum_MPTCPOption.DSS:
214
- return SchemaField(length=pkt['test']['length'], schema=MPTCPDSS)
215
- if subtype == Enum_MPTCPOption.ADD_ADDR:
216
- return SchemaField(length=pkt['test']['length'], schema=MPTCPAddAddress)
217
- if subtype == Enum_MPTCPOption.REMOVE_ADDR:
218
- return SchemaField(length=pkt['test']['length'], schema=MPTCPRemoveAddress)
219
- if subtype == Enum_MPTCPOption.MP_PRIO:
220
- return SchemaField(length=pkt['test']['length'], schema=MPTCPPriority)
221
- if subtype == Enum_MPTCPOption.MP_FAIL:
222
- return SchemaField(length=pkt['test']['length'], schema=MPTCPFallback)
223
- if subtype == Enum_MPTCPOption.MP_FASTCLOSE:
224
- return SchemaField(length=pkt['test']['length'], schema=MPTCPFastclose)
225
- return SchemaField(length=pkt['test']['length'], schema=MPTCPUnknown)
206
+ schema = MPTCPJoinSYN
207
+ elif pkt['flags']['syn'] == 1 and pkt['flags']['ack'] == 1:
208
+ schema = MPTCPJoinSYNACK
209
+ elif pkt['flags']['syn'] == 0 and pkt['flags']['ack'] == 1:
210
+ schema = MPTCPJoinACK
211
+ else:
212
+ raise FieldError(f'TCP: [OptNo {Enum_Option.Multipath_TCP}] {Enum_MPTCPOption.MP_JOIN} invalid flags')
213
+ return SchemaField(length=pkt['test']['length'], schema=schema)
226
214
 
227
215
 
228
216
  def mptcp_add_address_selector(pkt: 'dict[str, Any]') -> 'Field':
@@ -296,9 +284,11 @@ class PortEnumField(EnumField):
296
284
  return self._namespace.get(value, proto=Enum_TransportProtocol.tcp)
297
285
 
298
286
 
299
- class Option(Schema):
287
+ class Option(EnumSchema[Enum_Option]):
300
288
  """Header schema for TCP options."""
301
289
 
290
+ __default__ = lambda: UnassignedOption
291
+
302
292
  #: Option kind.
303
293
  kind: 'Enum_Option' = EnumField(length=1, namespace=Enum_Option)
304
294
  #: Option length.
@@ -335,7 +325,7 @@ class UnassignedOption(Option):
335
325
 
336
326
 
337
327
  @schema_final
338
- class EndOfOptionList(Option):
328
+ class EndOfOptionList(Option, code=Enum_Option.End_of_Option_List):
339
329
  """Header schema for TCP end of option list."""
340
330
 
341
331
  if TYPE_CHECKING:
@@ -343,7 +333,7 @@ class EndOfOptionList(Option):
343
333
 
344
334
 
345
335
  @schema_final
346
- class NoOperation(Option):
336
+ class NoOperation(Option, code=Enum_Option.No_Operation):
347
337
  """Header schema for TCP no operation."""
348
338
 
349
339
  if TYPE_CHECKING:
@@ -351,7 +341,7 @@ class NoOperation(Option):
351
341
 
352
342
 
353
343
  @schema_final
354
- class MaximumSegmentSize(Option):
344
+ class MaximumSegmentSize(Option, code=Enum_Option.Maximum_Segment_Size):
355
345
  """Header schema for TCP max segment size option."""
356
346
 
357
347
  #: Maximum segment size.
@@ -362,7 +352,7 @@ class MaximumSegmentSize(Option):
362
352
 
363
353
 
364
354
  @schema_final
365
- class WindowScale(Option):
355
+ class WindowScale(Option, code=Enum_Option.Window_Scale):
366
356
  """Header schema for TCP window scale option."""
367
357
 
368
358
  #: Window scale (shift count).
@@ -373,7 +363,7 @@ class WindowScale(Option):
373
363
 
374
364
 
375
365
  @schema_final
376
- class SACKPermitted(Option):
366
+ class SACKPermitted(Option, code=Enum_Option.SACK_Permitted):
377
367
  """Header schema for TCP SACK permitted option."""
378
368
 
379
369
  if TYPE_CHECKING:
@@ -394,7 +384,7 @@ class SACKBlock(Schema):
394
384
 
395
385
 
396
386
  @schema_final
397
- class SACK(Option):
387
+ class SACK(Option, code=Enum_Option.SACK):
398
388
  """Header schema for TCP SACK option."""
399
389
 
400
390
  #: Selected ACK data.
@@ -408,7 +398,7 @@ class SACK(Option):
408
398
 
409
399
 
410
400
  @schema_final
411
- class Echo(Option):
401
+ class Echo(Option, code=Enum_Option.Echo):
412
402
  """Header schema for TCP echo option."""
413
403
 
414
404
  #: Info to be echoed.
@@ -419,7 +409,7 @@ class Echo(Option):
419
409
 
420
410
 
421
411
  @schema_final
422
- class EchoReply(Option):
412
+ class EchoReply(Option, code=Enum_Option.Echo_Reply):
423
413
  """Header schema for TCP echo reply option."""
424
414
 
425
415
  #: Echoed info.
@@ -430,7 +420,7 @@ class EchoReply(Option):
430
420
 
431
421
 
432
422
  @schema_final
433
- class Timestamp(Option):
423
+ class Timestamps(Option, code=Enum_Option.Timestamps):
434
424
  """Header schema for TCP timestamps option."""
435
425
 
436
426
  #: Timestamp value.
@@ -443,7 +433,7 @@ class Timestamp(Option):
443
433
 
444
434
 
445
435
  @schema_final
446
- class PartialOrderConnectionPermitted(Option):
436
+ class PartialOrderConnectionPermitted(Option, code=Enum_Option.Partial_Order_Connection_Permitted):
447
437
  """Header schema for TCP partial order connection permitted option."""
448
438
 
449
439
  if TYPE_CHECKING:
@@ -451,7 +441,7 @@ class PartialOrderConnectionPermitted(Option):
451
441
 
452
442
 
453
443
  @schema_final
454
- class PartialOrderConnectionProfile(Option):
444
+ class PartialOrderServiceProfile(Option, code=Enum_Option.Partial_Order_Service_Profile):
455
445
  """Header schema for TCP partial order connection service profile option."""
456
446
 
457
447
  #: Profile data.
@@ -465,7 +455,7 @@ class PartialOrderConnectionProfile(Option):
465
455
 
466
456
 
467
457
  @schema_final
468
- class CC(Option):
458
+ class CC(Option, code=Enum_Option.CC):
469
459
  """Header schema for TCP CC option."""
470
460
 
471
461
  #: Connection count.
@@ -476,7 +466,7 @@ class CC(Option):
476
466
 
477
467
 
478
468
  @schema_final
479
- class CCNew(Option):
469
+ class CCNew(Option, code=Enum_Option.CC_NEW):
480
470
  """Header schema for TCP connection count (new) option."""
481
471
 
482
472
  #: Connection count.
@@ -487,7 +477,7 @@ class CCNew(Option):
487
477
 
488
478
 
489
479
  @schema_final
490
- class CCEcho(Option):
480
+ class CCEcho(Option, code=Enum_Option.CC_ECHO):
491
481
  """Header schema for TCP connection count (echo) option."""
492
482
 
493
483
  #: Connection count.
@@ -498,7 +488,7 @@ class CCEcho(Option):
498
488
 
499
489
 
500
490
  @schema_final
501
- class AlternateChecksumRequest(Option):
491
+ class AlternateChecksumRequest(Option, code=Enum_Option.TCP_Alternate_Checksum_Request):
502
492
  """Header schema for TCP alternate checksum request option."""
503
493
 
504
494
  #: Checksum algorithm.
@@ -509,7 +499,7 @@ class AlternateChecksumRequest(Option):
509
499
 
510
500
 
511
501
  @schema_final
512
- class AlternateChecksumData(Option):
502
+ class AlternateChecksumData(Option, code=Enum_Option.TCP_Alternate_Checksum_Data):
513
503
  """Header schema for TCP alternate checksum data option."""
514
504
 
515
505
  #: Checksum data.
@@ -520,7 +510,7 @@ class AlternateChecksumData(Option):
520
510
 
521
511
 
522
512
  @schema_final
523
- class MD5Signature(Option):
513
+ class MD5Signature(Option, code=Enum_Option.MD5_Signature_Option):
524
514
  """Header schema for TCP MD5 signature option."""
525
515
 
526
516
  #: MD5 digest.
@@ -531,7 +521,7 @@ class MD5Signature(Option):
531
521
 
532
522
 
533
523
  @schema_final
534
- class QuickStartResponse(Option):
524
+ class QuickStartResponse(Option, code=Enum_Option.Quick_Start_Response):
535
525
  """Header schema for TCP quick start response option."""
536
526
 
537
527
  #: Flags.
@@ -550,7 +540,7 @@ class QuickStartResponse(Option):
550
540
 
551
541
 
552
542
  @schema_final
553
- class UserTimeout(Option):
543
+ class UserTimeout(Option, code=Enum_Option.User_Timeout_Option):
554
544
  """Header schema for TCP user timeout option."""
555
545
 
556
546
  #: Granularity and user timeout.
@@ -564,7 +554,7 @@ class UserTimeout(Option):
564
554
 
565
555
 
566
556
  @schema_final
567
- class Authentication(Option):
557
+ class Authentication(Option, code=Enum_Option.TCP_Authentication_Option):
568
558
  """Header schema for TCP authentication option."""
569
559
 
570
560
  #: Key ID.
@@ -607,9 +597,15 @@ class _MPTCP(Schema):
607
597
  return ret
608
598
 
609
599
 
610
- class MPTCP(Option):
600
+ # register ``_MPTCP`` as ``Multipath_TCP`` option
601
+ Option.register(Enum_Option.Multipath_TCP, _MPTCP)
602
+
603
+
604
+ class MPTCP(EnumSchema[Enum_MPTCPOption]):
611
605
  """Header schema for Multipath TCP options."""
612
606
 
607
+ __enum__: 'DefaultDict[Enum_MPTCPOption, Type[MPTCP]]' = collections.defaultdict(lambda: MPTCPUnknown)
608
+
613
609
  if TYPE_CHECKING:
614
610
  #: MPTCP subtype.
615
611
  subtype: 'Enum_MPTCPOption'
@@ -632,7 +628,7 @@ class MPTCPUnknown(MPTCP):
632
628
 
633
629
 
634
630
  @schema_final
635
- class MPTCPCapable(MPTCP):
631
+ class MPTCPCapable(MPTCP, code=Enum_MPTCPOption.MP_CAPABLE):
636
632
  """Header schema for Multipath TCP capable option."""
637
633
 
638
634
  #: Subtype and version.
@@ -658,7 +654,7 @@ class MPTCPCapable(MPTCP):
658
654
  def __init__(self, kind: 'Enum_Option', length: 'int', test: 'MPTCPSubtypeCapable', flags: 'MPTCPCapableFlags', skey: 'int', rkey: 'Optional[int]') -> 'None': ...
659
655
 
660
656
 
661
- class MPTCPJoin(MPTCP):
657
+ class MPTCPJoin(MPTCP, code=Enum_MPTCPOption.MP_JOIN): # register as a placeholder
662
658
  """Header schema for Multipath TCP join option."""
663
659
 
664
660
 
@@ -720,7 +716,7 @@ class MPTCPJoinACK(MPTCPJoin):
720
716
 
721
717
 
722
718
  @schema_final
723
- class MPTCPDSS(MPTCP):
719
+ class MPTCPDSS(MPTCP, code=Enum_MPTCPOption.DSS):
724
720
  """Header schema for Multipath TCP DSS option."""
725
721
 
726
722
  #: Subtype and flags.
@@ -766,7 +762,7 @@ class MPTCPDSS(MPTCP):
766
762
 
767
763
 
768
764
  @schema_final
769
- class MPTCPAddAddress(MPTCP):
765
+ class MPTCPAddAddress(MPTCP, code=Enum_MPTCPOption.ADD_ADDR):
770
766
  """Header schema for Multipath TCP add address option."""
771
767
 
772
768
  #: Subtype and IP version.
@@ -791,7 +787,7 @@ class MPTCPAddAddress(MPTCP):
791
787
 
792
788
 
793
789
  @schema_final
794
- class MPTCPRemoveAddress(MPTCP):
790
+ class MPTCPRemoveAddress(MPTCP, code=Enum_MPTCPOption.REMOVE_ADDR):
795
791
  """Header schema for Multipath TCP remove address option."""
796
792
 
797
793
  #: Subtype.
@@ -809,7 +805,7 @@ class MPTCPRemoveAddress(MPTCP):
809
805
 
810
806
 
811
807
  @schema_final
812
- class MPTCPPriority(MPTCP):
808
+ class MPTCPPriority(MPTCP, code=Enum_MPTCPOption.MP_PRIO):
813
809
  """Header schema for Multipath TCP priority option."""
814
810
 
815
811
  #: Subtype.
@@ -828,7 +824,7 @@ class MPTCPPriority(MPTCP):
828
824
 
829
825
 
830
826
  @schema_final
831
- class MPTCPFallback(MPTCP):
827
+ class MPTCPFallback(MPTCP, code=Enum_MPTCPOption.MP_FAIL):
832
828
  """Header schema for Multipath TCP fallback option."""
833
829
 
834
830
  #: Subtype.
@@ -843,7 +839,7 @@ class MPTCPFallback(MPTCP):
843
839
 
844
840
 
845
841
  @schema_final
846
- class MPTCPFastclose(MPTCP):
842
+ class MPTCPFastclose(MPTCP, code=Enum_MPTCPOption.MP_FASTCLOSE):
847
843
  """Header schema for Multipath TCP fastclose option."""
848
844
 
849
845
  #: Subtype.
@@ -858,7 +854,7 @@ class MPTCPFastclose(MPTCP):
858
854
 
859
855
 
860
856
  @schema_final
861
- class FastOpenCookie(Option):
857
+ class FastOpenCookie(Option, code=Enum_Option.TCP_Fast_Open_Cookie):
862
858
  """"Header schema for TCP Fast Open option."""
863
859
 
864
860
  #: Cookie.
@@ -910,31 +906,8 @@ class TCP(Schema):
910
906
  length=lambda pkt: pkt['offset']['offset'] * 4 - 20,
911
907
  base_schema=Option,
912
908
  type_name='kind',
909
+ registry=Option.registry,
913
910
  eool=Enum_Option.End_of_Option_List,
914
- registry=collections.defaultdict(lambda: UnassignedOption, {
915
- Enum_Option.End_of_Option_List: EndOfOptionList,
916
- Enum_Option.No_Operation: NoOperation,
917
- Enum_Option.Maximum_Segment_Size: MaximumSegmentSize,
918
- Enum_Option.Window_Scale: WindowScale,
919
- Enum_Option.SACK_Permitted: SACKPermitted,
920
- Enum_Option.SACK: SACK,
921
- Enum_Option.Echo: Echo,
922
- Enum_Option.Echo_Reply: EchoReply,
923
- Enum_Option.Timestamps: Timestamp,
924
- Enum_Option.Partial_Order_Connection_Permitted: PartialOrderConnectionPermitted,
925
- Enum_Option.Partial_Order_Service_Profile: PartialOrderConnectionProfile,
926
- Enum_Option.CC: CC,
927
- Enum_Option.CC_NEW: CCNew,
928
- Enum_Option.CC_ECHO: CCEcho,
929
- Enum_Option.TCP_Alternate_Checksum_Request: AlternateChecksumRequest,
930
- Enum_Option.TCP_Alternate_Checksum_Data: AlternateChecksumData,
931
- Enum_Option.MD5_Signature_Option: MD5Signature,
932
- Enum_Option.Quick_Start_Response: QuickStartResponse,
933
- Enum_Option.User_Timeout_Option: UserTimeout,
934
- Enum_Option.TCP_Authentication_Option: Authentication,
935
- Enum_Option.Multipath_TCP: _MPTCP,
936
- Enum_Option.TCP_Fast_Open_Cookie: FastOpenCookie,
937
- }),
938
911
  )
939
912
  #: Padding.
940
913
  padding: 'bytes' = PaddingField(length=lambda pkt: pkt.get('__option_padding__', 0)) # key generated by OptionField
@@ -82,11 +82,11 @@ from pcapkit.protocols.data.transport.tcp import NoOperation as Data_NoOperation
82
82
  from pcapkit.protocols.data.transport.tcp import \
83
83
  PartialOrderConnectionPermitted as Data_PartialOrderConnectionPermitted
84
84
  from pcapkit.protocols.data.transport.tcp import \
85
- PartialOrderConnectionProfile as Data_PartialOrderConnectionProfile
85
+ PartialOrderServiceProfile as Data_PartialOrderServiceProfile
86
86
  from pcapkit.protocols.data.transport.tcp import QuickStartResponse as Data_QuickStartResponse
87
87
  from pcapkit.protocols.data.transport.tcp import SACKBlock as Data_SACKBlock
88
88
  from pcapkit.protocols.data.transport.tcp import SACKPermitted as Data_SACKPermitted
89
- from pcapkit.protocols.data.transport.tcp import Timestamp as Data_Timestamp
89
+ from pcapkit.protocols.data.transport.tcp import Timestamps as Data_Timestamps
90
90
  from pcapkit.protocols.data.transport.tcp import UnassignedOption as Data_UnassignedOption
91
91
  from pcapkit.protocols.data.transport.tcp import UserTimeout as Data_UserTimeout
92
92
  from pcapkit.protocols.data.transport.tcp import WindowScale as Data_WindowScale
@@ -121,11 +121,11 @@ from pcapkit.protocols.schema.transport.tcp import NoOperation as Schema_NoOpera
121
121
  from pcapkit.protocols.schema.transport.tcp import \
122
122
  PartialOrderConnectionPermitted as Schema_PartialOrderConnectionPermitted
123
123
  from pcapkit.protocols.schema.transport.tcp import \
124
- PartialOrderConnectionProfile as Schema_PartialOrderConnectionProfile
124
+ PartialOrderServiceProfile as Schema_PartialOrderServiceProfile
125
125
  from pcapkit.protocols.schema.transport.tcp import QuickStartResponse as Schema_QuickStartResponse
126
126
  from pcapkit.protocols.schema.transport.tcp import SACKBlock as Schema_SACKBlock
127
127
  from pcapkit.protocols.schema.transport.tcp import SACKPermitted as Schema_SACKPermitted
128
- from pcapkit.protocols.schema.transport.tcp import Timestamp as Schema_Timestamp
128
+ from pcapkit.protocols.schema.transport.tcp import Timestamps as Schema_Timestamps
129
129
  from pcapkit.protocols.schema.transport.tcp import UnassignedOption as Schema_UnassignedOption
130
130
  from pcapkit.protocols.schema.transport.tcp import UserTimeout as Schema_UserTimeout
131
131
  from pcapkit.protocols.schema.transport.tcp import WindowScale as Schema_WindowScale
@@ -960,7 +960,7 @@ class TCP(Transport[Data_TCP, Schema_TCP],
960
960
  )
961
961
  return data
962
962
 
963
- def _read_mode_ts(self, schema: 'Schema_Timestamp', *, options: 'Option') -> 'Data_Timestamp': # pylint: disable=unused-argument
963
+ def _read_mode_ts(self, schema: 'Schema_Timestamps', *, options: 'Option') -> 'Data_Timestamps': # pylint: disable=unused-argument
964
964
  """Read TCP timestamps option.
965
965
 
966
966
  Structure of TCP timestamp option [:rfc:`7323`]:
@@ -986,7 +986,7 @@ class TCP(Transport[Data_TCP, Schema_TCP],
986
986
  if schema.length != 10:
987
987
  raise ProtocolError(f'{self.alias}: [OptNo {schema.kind}] invalid format')
988
988
 
989
- data = Data_Timestamp(
989
+ data = Data_Timestamps(
990
990
  kind=schema.kind,
991
991
  length=schema.length,
992
992
  timestamp=schema.value,
@@ -1024,7 +1024,7 @@ class TCP(Transport[Data_TCP, Schema_TCP],
1024
1024
  length=schema.length,
1025
1025
  )
1026
1026
 
1027
- def _read_mode_pocsp(self, schema: 'Schema_PartialOrderConnectionProfile', *, options: 'Option') -> 'Data_PartialOrderConnectionProfile': # pylint: disable=unused-argument
1027
+ def _read_mode_pocsp(self, schema: 'Schema_PartialOrderServiceProfile', *, options: 'Option') -> 'Data_PartialOrderServiceProfile': # pylint: disable=unused-argument
1028
1028
  """Read TCP partial order connection service profile option.
1029
1029
 
1030
1030
  Structure of TCP ``POC-SP`` option [:rfc:`1693`][:rfc:`6247`]:
@@ -1050,7 +1050,7 @@ class TCP(Transport[Data_TCP, Schema_TCP],
1050
1050
  if schema.length != 3:
1051
1051
  raise ProtocolError(f'{self.alias}: [OptNo {schema.kind}] invalid format')
1052
1052
 
1053
- data = Data_PartialOrderConnectionProfile(
1053
+ data = Data_PartialOrderServiceProfile(
1054
1054
  kind=schema.kind,
1055
1055
  length=schema.length,
1056
1056
  start=bool(schema.profile['start']),
@@ -2206,10 +2206,10 @@ class TCP(Transport[Data_TCP, Schema_TCP],
2206
2206
  data=data,
2207
2207
  )
2208
2208
 
2209
- def _make_mode_ts(self, code: 'Enum_Option', opt: 'Optional[Data_Timestamp]' = None, *,
2209
+ def _make_mode_ts(self, code: 'Enum_Option', opt: 'Optional[Data_Timestamps]' = None, *,
2210
2210
  tsval: 'int' = 0,
2211
2211
  tsecr: 'int' = 0,
2212
- **kwargs: 'Any') -> 'Schema_Timestamp':
2212
+ **kwargs: 'Any') -> 'Schema_Timestamps':
2213
2213
  """Make TCP timestamps option.
2214
2214
 
2215
2215
  Args:
@@ -2227,7 +2227,7 @@ class TCP(Transport[Data_TCP, Schema_TCP],
2227
2227
  tsval = opt.timestamp
2228
2228
  tsecr = opt.echo
2229
2229
 
2230
- return Schema_Timestamp(
2230
+ return Schema_Timestamps(
2231
2231
  kind=code,
2232
2232
  length=10,
2233
2233
  value=tsval,
@@ -2252,10 +2252,10 @@ class TCP(Transport[Data_TCP, Schema_TCP],
2252
2252
  length=2,
2253
2253
  )
2254
2254
 
2255
- def _make_mode_pocsp(self, code: 'Enum_Option', opt: 'Optional[Data_PartialOrderConnectionProfile]' = None, *,
2255
+ def _make_mode_pocsp(self, code: 'Enum_Option', opt: 'Optional[Data_PartialOrderServiceProfile]' = None, *,
2256
2256
  start: 'bool' = False,
2257
2257
  end: 'bool' = False,
2258
- **kwargs: 'Any') -> 'Schema_PartialOrderConnectionProfile':
2258
+ **kwargs: 'Any') -> 'Schema_PartialOrderServiceProfile':
2259
2259
  """Make TCP partial order connection service profile option.
2260
2260
 
2261
2261
  Args:
@@ -2273,7 +2273,7 @@ class TCP(Transport[Data_TCP, Schema_TCP],
2273
2273
  start = opt.start
2274
2274
  end = opt.end
2275
2275
 
2276
- return Schema_PartialOrderConnectionProfile(
2276
+ return Schema_PartialOrderServiceProfile(
2277
2277
  kind=code,
2278
2278
  length=3,
2279
2279
  profile={
@@ -46,7 +46,7 @@ from aenum import StrEnum, extend_enum
46
46
  __all__ = ['{NAME}']
47
47
 
48
48
  if TYPE_CHECKING:
49
- from typing import DefaultDict, Optional, Type
49
+ from typing import Any, DefaultDict, Optional, Type
50
50
 
51
51
 
52
52
  class {NAME}(StrEnum):
@@ -62,7 +62,7 @@ class {NAME}(StrEnum):
62
62
  __members_ns__: 'DefaultDict[str, dict[int, {NAME}]]' = defaultdict(dict)
63
63
 
64
64
  def __new__(cls, value: 'int', name: 'str' = 'opt_unknown') -> 'Type[{NAME}]':
65
- temp = '%d_%s' % (value, name)
65
+ temp = '%s [%d]' % (name, value)
66
66
 
67
67
  obj = str.__new__(cls, temp)
68
68
  obj._value_ = temp
@@ -78,6 +78,33 @@ class {NAME}(StrEnum):
78
78
  def __repr__(self) -> 'str':
79
79
  return "<%s.%s: %d>" % (self.__class__.__name__, self.opt_name, self.opt_value)
80
80
 
81
+ def __str__(self) -> 'str':
82
+ return '%s [%d]' % (self.opt_name, self.opt_value)
83
+
84
+ def __int__(self) -> 'int':
85
+ return self.opt_value
86
+
87
+ def __lt__(self, other: '{NAME}') -> 'bool':
88
+ return self.opt_value < other
89
+
90
+ def __gt__(self, other: '{NAME}') -> 'bool':
91
+ return self.opt_value > other
92
+
93
+ def __le__(self, other: '{NAME}') -> 'bool':
94
+ return self.opt_value <= other
95
+
96
+ def __ge__(self, other: '{NAME}') -> 'bool':
97
+ return self.opt_value >= other
98
+
99
+ def __eq__(self, other: 'Any') -> 'bool':
100
+ return self.opt_value == other
101
+
102
+ def __ne__(self, other: 'Any') -> 'bool':
103
+ return self.opt_value != other
104
+
105
+ def __hash__(self) -> 'int':
106
+ return hash(self.opt_value)
107
+
81
108
  {ENUM}
82
109
 
83
110
  @staticmethod
@@ -47,7 +47,7 @@ from pcapkit.utilities.compat import show_flag_values
47
47
  __all__ = ['{NAME}']
48
48
 
49
49
  if TYPE_CHECKING:
50
- from typing import DefaultDict, Type
50
+ from typing import Any, DefaultDict, Type
51
51
 
52
52
 
53
53
  class TransportProtocol(IntFlag):
@@ -97,7 +97,7 @@ class {NAME}(StrEnum):
97
97
 
98
98
  def __new__(cls, value: 'int', name: 'str' = '<null>',
99
99
  proto: 'TransportProtocol' = TransportProtocol.undefined) -> 'Type[{NAME}]':
100
- temp = '%s_%d_%s' % (proto.name, value, name)
100
+ temp = '%s [%d - %s]' % (name, value, proto.name)
101
101
 
102
102
  obj = str.__new__(cls, temp)
103
103
  obj._value_ = temp
@@ -116,6 +116,33 @@ class {NAME}(StrEnum):
116
116
  def __repr__(self) -> 'str':
117
117
  return "<%s.%s: %d [%s]>" % (self.__class__.__name__, self.svc, self.port, self.proto.name)
118
118
 
119
+ def __str__(self) -> 'str':
120
+ return '%s [%d - %s]' % (self.svc, self.port, self.proto.name)
121
+
122
+ def __int__(self) -> 'int':
123
+ return self.opt_value
124
+
125
+ def __lt__(self, other: '{NAME}') -> 'bool':
126
+ return self.opt_value < other
127
+
128
+ def __gt__(self, other: '{NAME}') -> 'bool':
129
+ return self.opt_value > other
130
+
131
+ def __le__(self, other: '{NAME}') -> 'bool':
132
+ return self.opt_value <= other
133
+
134
+ def __ge__(self, other: '{NAME}') -> 'bool':
135
+ return self.opt_value >= other
136
+
137
+ def __eq__(self, other: 'Any') -> 'bool':
138
+ return self.opt_value == other
139
+
140
+ def __ne__(self, other: 'Any') -> 'bool':
141
+ return self.opt_value != other
142
+
143
+ def __hash__(self) -> 'int':
144
+ return hash(self.opt_value)
145
+
119
146
  {ENUM}
120
147
 
121
148
  @staticmethod
@@ -226,7 +253,10 @@ class AppType(Vendor):
226
253
  if renm in line:
227
254
  if port == line[renm][1]:
228
255
  line[renm][2] = f'{line[renm][2]} | {proto}'
229
- line[renm][3] = f'{line[renm][3]}\n #: {cmmt}'
256
+ if line[renm][3].startswith('-'):
257
+ line[renm][3] = f'{line[renm][3]}\n #: - {cmmt}'
258
+ else:
259
+ line[renm][3] = f'- {line[renm][3]}\n #: - {cmmt}'
230
260
  else:
231
261
  line[f'{renm}_{line[renm][1]}'] = line[renm]
232
262
  line[f'{renm}_{code}'] = [svc, port, proto, cmmt]
@@ -254,7 +284,7 @@ class AppType(Vendor):
254
284
  if keyword.iskeyword(key):
255
285
  key = '%s_' % key
256
286
 
257
- pres = f'{key} = {code}, {svc!r}, {proto}'
287
+ pres = f"{key}: 'AppType' = {code}, {svc!r}, {proto}"
258
288
  sufs = f'#: {cmmt}'
259
289
 
260
290
  enum.append(f'{sufs}\n {pres}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pypcapkit
3
- Version: 1.0.3
3
+ Version: 1.1.0
4
4
  Summary: PyPCAPKit: comprehensive network packet analysis library
5
5
  Author-email: Jarry Shaw <jarryshaw@icloud.com>
6
6
  Maintainer: Jarry Shaw