Skip to content

Commit 4b46cf5

Browse files
committed
working on MH protocol impl (options)
1 parent 1319659 commit 4b46cf5

File tree

5 files changed

+334
-4
lines changed

5 files changed

+334
-4
lines changed

pcapkit/protocols/data/internet/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@
191191
from pcapkit.protocols.data.internet.mh import CGAParametersOption as MH_CGAParametersOption
192192
from pcapkit.protocols.data.internet.mh import UnknownExtension as MH_UnknownExtension
193193
from pcapkit.protocols.data.internet.mh import MultiPrefixExtension as MH_MultiPrefixExtension
194+
from pcapkit.protocols.data.internet.mh import SignatureOption as MH_SignatureOption
195+
from pcapkit.protocols.data.internet.mh import PermanentHomeKeygenTokenOption as MH_PermanentHomeKeygenTokenOption
196+
from pcapkit.protocols.data.internet.mh import CareofTestInitOption as MH_CareofTestInitOption
197+
from pcapkit.protocols.data.internet.mh import CareofTestOption as MH_CareofTestOption
194198

195199
__all__ = [
196200
# Authentication Header

pcapkit/protocols/data/internet/mh.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
'UnassignedOption', 'PadOption', 'BindRefreshAdviceOption', 'AlternateCareofAddressOption',
7070
'NonceIndicesOption', 'BindingAuthorizationDataOption', 'MobileNetworkPrefixOption',
7171
'LinkLayerAddressOption', 'MNIDOption', 'AuthOption', 'MesgIDOption', 'CGAParametersRequestOption',
72-
'CGAParametersOption',
72+
'CGAParametersOption', 'SignatureOption', 'PermanentHomeKeygenTokenOption', 'CareofTestInitOption',
7373

7474
'CGAParameter',
7575

@@ -308,3 +308,44 @@ class CGAParametersOption(Option):
308308

309309
if TYPE_CHECKING:
310310
def __init__(self, type: 'Enum_Option', length: 'int', parameters: 'tuple[CGAParameter, ...]') -> 'None': ...
311+
312+
313+
@info_final
314+
class SignatureOption(Option):
315+
"""Data model for MH Signature option."""
316+
317+
#: Signature.
318+
signature: 'bytes'
319+
320+
if TYPE_CHECKING:
321+
def __init__(self, type: 'Enum_Option', length: 'int', signature: 'bytes') -> 'None': ...
322+
323+
324+
@info_final
325+
class PermanentHomeKeygenTokenOption(Option):
326+
"""Data model for Permanent Home Keygen Token option."""
327+
328+
#: Permanent home keygen token.
329+
token: 'bytes'
330+
331+
if TYPE_CHECKING:
332+
def __init__(self, type: 'Enum_Option', length: 'int', token: 'bytes') -> 'None': ...
333+
334+
335+
@info_final
336+
class CareofTestInitOption(Option):
337+
"""Header schema for MH Care-of Test Init options."""
338+
339+
if TYPE_CHECKING:
340+
def __init__(self, type: 'Enum_Option', length: 'int') -> 'None': ...
341+
342+
343+
@info_final
344+
class CareofTestOption(Option):
345+
"""Header schema for MH Care-of Test options."""
346+
347+
#: Care-of keygen token.
348+
token: 'bytes'
349+
350+
if TYPE_CHECKING:
351+
def __init__(self, type: 'Enum_Option', length: 'int', token: 'bytes') -> 'None': ...

pcapkit/protocols/internet/mh.py

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@
124124
from pcapkit.utilities.exceptions import ProtocolError, UnsupportedCall
125125
from pcapkit.utilities.warnings import ProtocolWarning, warn
126126

127+
from pcapkit.protocols.schema.internet.mh import SignatureOption as Schema_SignatureOption
128+
from pcapkit.protocols.data.internet.mh import SignatureOption as Data_SignatureOption
129+
from pcapkit.protocols.schema.internet.mh import PermanentHomeKeygenTokenOption as Schema_PermanentHomeKeygenTokenOption
130+
from pcapkit.protocols.data.internet.mh import PermanentHomeKeygenTokenOption as Data_PermanentHomeKeygenTokenOption
131+
from pcapkit.protocols.schema.internet.mh import CareofTestInitOption as Schema_CareofTestInitOption
132+
from pcapkit.protocols.data.internet.mh import CareofTestInitOption as Data_CareofTestInitOption
133+
from pcapkit.protocols.schema.internet.mh import CareofTestOption as Schema_CareofTestOption
134+
from pcapkit.protocols.data.internet.mh import CareofTestOption as Data_CareofTestOption
135+
127136
if TYPE_CHECKING:
128137
from datetime import datetime as dt_type
129138
from enum import IntEnum as StdlibEnum
@@ -204,6 +213,10 @@ class MH(Internet[Data_MH, Schema_MH],
204213
Enum_Option.MESG_ID_OPTION_TYPE: 'mesg_id',
205214
Enum_Option.CGA_Parameters_Request: 'cga_pr',
206215
Enum_Option.CGA_Parameters: 'cga_param',
216+
Enum_Option.Signature: 'signature',
217+
Enum_Option.Permanent_Home_Keygen_Token: 'phkt',
218+
Enum_Option.Care_of_Test_Init: 'ct_init',
219+
Enum_Option.Care_of_Test: 'ct',
207220
},
208221
) # type: DefaultDict[Enum_Option | int, str | tuple[OptionParser, OptionConstructor]]
209222

@@ -945,6 +958,143 @@ def _read_opt_cga_param(self, schema: 'Schema_CGAParametersOption', *,
945958
)
946959
return data
947960

961+
def _read_opt_signature(self, schema: 'Schema_SignatureOption', *,
962+
options: 'Option') -> 'Data_SignatureOption':
963+
"""Read MH signature option.
964+
965+
Structure of MH Signature option [:rfc:`4866`]:
966+
967+
.. code-block:: text
968+
969+
0 1 2 3
970+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
971+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
972+
| Option Type | Option Length |
973+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
974+
| |
975+
: :
976+
: Signature :
977+
: :
978+
| |
979+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
980+
981+
Args:
982+
schema: Parsed option schema.
983+
options: Parsed MH options.
984+
985+
Returns:
986+
Constructed option data.
987+
988+
"""
989+
data = Data_SignatureOption(
990+
type=schema.type,
991+
length=schema.length + 2,
992+
signature=schema.signature,
993+
)
994+
return data
995+
996+
def _read_opt_phkt(self, schema: 'Schema_PermanentHomeKeygenTokenOption', *,
997+
options: 'Option') -> 'Data_PermanentHomeKeygenTokenOption':
998+
"""Read MH permanent home keygen token option.
999+
1000+
Structure of MH Permanent Home Keygen Token option [:rfc:`4866`]:
1001+
1002+
.. code-block:: text
1003+
1004+
0 1 2 3
1005+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1006+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1007+
| Option Type | Option Length |
1008+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1009+
| |
1010+
: :
1011+
: Permanent Home Keygen Token :
1012+
: :
1013+
| |
1014+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1015+
1016+
Args:
1017+
schema: Parsed option schema.
1018+
options: Parsed MH options.
1019+
1020+
Returns:
1021+
Constructed option data.
1022+
1023+
"""
1024+
data = Data_PermanentHomeKeygenTokenOption(
1025+
type=schema.type,
1026+
length=schema.length + 2,
1027+
token=schema.token,
1028+
)
1029+
return data
1030+
1031+
def _read_opt_ct_init(self, schema: 'Schema_CareofTestInitOption', *,
1032+
options: 'Option') -> 'Data_CareofTestInitOption':
1033+
"""Read MH Care-of Test Init option.
1034+
1035+
Structure of MH Care-of Test Init option [:rfc:`4866`]:
1036+
1037+
.. code-block:: text
1038+
1039+
0 1 2 3
1040+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1041+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1042+
| Option Type | Option Length |
1043+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1044+
1045+
Args:
1046+
schema: Parsed option schema.
1047+
options: Parsed MH options.
1048+
1049+
Returns:
1050+
Constructed option data.
1051+
1052+
"""
1053+
if schema.length != 0:
1054+
raise ProtocolError(f'{self.alias}: [Opt {schema.type}] invalid format')
1055+
1056+
data = Data_CareofTestInitOption(
1057+
type=schema.type,
1058+
length=schema.length + 2,
1059+
)
1060+
return data
1061+
1062+
def _read_opt_ct(self, schema: 'Schema_CareofTestOption', *,
1063+
options: 'Option') -> 'Data_CareofTestOption':
1064+
"""Read MH Care-of Test option.
1065+
1066+
Structure of MH Care-of Test option [:rfc:`4866`]:
1067+
1068+
.. code-block:: text
1069+
1070+
0 1 2 3
1071+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1072+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1073+
| Option Type | Option Length |
1074+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1075+
| |
1076+
+ Care-of Keygen Token +
1077+
| |
1078+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1079+
1080+
Args:
1081+
schema: Parsed option schema.
1082+
options: Parsed MH options.
1083+
1084+
Returns:
1085+
Constructed option data.
1086+
1087+
"""
1088+
if schema.length != 8:
1089+
raise ProtocolError(f'{self.alias}: [Opt {schema.type}] invalid format')
1090+
1091+
data = Data_CareofTestOption(
1092+
type=schema.type,
1093+
length=schema.length + 2,
1094+
token=schema.token,
1095+
)
1096+
return data
1097+
9481098

9491099

9501100

@@ -1525,6 +1675,97 @@ def _make_opt_cga_param(self, type: 'Enum_Option', option: 'Optional[Data_CGAPar
15251675
parameters=param,
15261676
)
15271677

1678+
def _make_opt_signature(self, type: 'Enum_Option', option: 'Optional[Data_SignatureOption]' = None, *,
1679+
signature: 'bytes' = b'',
1680+
**kwargs: 'Any') -> 'Schema_SignatureOption':
1681+
"""Make MH signature option.
1682+
1683+
Args:
1684+
type: Option type.
1685+
option: Option data model.
1686+
signature: Signature data.
1687+
**kwargs: Arbitrary keyword arguments.
1688+
1689+
Returns:
1690+
Constructed option schema.
1691+
1692+
"""
1693+
if option is not None:
1694+
signature = option.signature
1695+
1696+
return Schema_SignatureOption(
1697+
type=type,
1698+
length=len(signature),
1699+
signature=signature,
1700+
)
1701+
1702+
def _make_opt_phkt(self, type: 'Enum_Option', option: 'Optional[Data_PermanentHomeKeygenTokenOption]' = None, *,
1703+
token: 'bytes' = b'',
1704+
**kwargs: 'Any') -> 'Schema_PermanentHomeKeygenTokenOption':
1705+
"""Make MH permanent home keygen token option.
1706+
1707+
Args:
1708+
type: Option type.
1709+
option: Option data model.
1710+
token: Token data.
1711+
**kwargs: Arbitrary keyword arguments.
1712+
1713+
Returns:
1714+
Constructed option schema.
1715+
1716+
"""
1717+
if option is not None:
1718+
token = option.token
1719+
1720+
return Schema_PermanentHomeKeygenTokenOption(
1721+
type=type,
1722+
length=len(token),
1723+
token=token,
1724+
)
1725+
1726+
def _make_opt_ct_init(self, type: 'Enum_Option', option: 'Optional[Data_CareofTestInitOption]' = None,
1727+
**kwargs: 'Any') -> 'Schema_CareofTestInitOption':
1728+
"""Make MH Care-of Test Init option.
1729+
1730+
Args:
1731+
type: Option type.
1732+
option: Option data model.
1733+
**kwargs: Arbitrary keyword arguments.
1734+
1735+
Returns:
1736+
Constructed option schema.
1737+
1738+
"""
1739+
return Schema_CareofTestInitOption(
1740+
type=type,
1741+
length=0,
1742+
)
1743+
1744+
def _make_opt_ct(self, type: 'Enum_Option', option: 'Optional[Data_CareofTestOption]' = None,
1745+
token: 'bytes' = b'\x00\x00\x00\x00\x00\x00\x00\x00',
1746+
**kwargs: 'Any') -> 'Schema_CareofTestOption':
1747+
"""Make MH Care-of Test option.
1748+
1749+
Args:
1750+
type: Option type.
1751+
option: Option data model.
1752+
token: Care-of keygen token.
1753+
**kwargs: Arbitrary keyword arguments.
1754+
1755+
Returns:
1756+
Constructed option schema.
1757+
1758+
"""
1759+
if option is not None:
1760+
token = option.token
1761+
1762+
return Schema_CareofTestOption(
1763+
type=type,
1764+
length=8,
1765+
token=token,
1766+
)
1767+
1768+
15281769

15291770

15301771

pcapkit/protocols/schema/internet/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@
189189
from pcapkit.protocols.schema.internet.mh import UnknownExtension as MH_UnknownExtension
190190
from pcapkit.protocols.schema.internet.mh import MultiPrefixExtension as MH_MultiPrefixExtension
191191
from pcapkit.protocols.schema.internet.mh import Packet as MH_Packet
192+
from pcapkit.protocols.schema.internet.mh import SignatureOption as MH_SignatureOption
193+
from pcapkit.protocols.schema.internet.mh import PermanentHomeKeygenTokenOption as MH_PermanentHomeKeygenTokenOption
194+
from pcapkit.protocols.schema.internet.mh import CareofTestInitOption as MH_CareofTestInitOption
195+
from pcapkit.protocols.schema.internet.mh import CareofTestOption as MH_CareofTestOption
192196

193197
__all__ = [
194198
# Authentication Header

0 commit comments

Comments
 (0)