|
124 | 124 | from pcapkit.utilities.exceptions import ProtocolError, UnsupportedCall
|
125 | 125 | from pcapkit.utilities.warnings import ProtocolWarning, warn
|
126 | 126 |
|
| 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 | + |
127 | 136 | if TYPE_CHECKING:
|
128 | 137 | from datetime import datetime as dt_type
|
129 | 138 | from enum import IntEnum as StdlibEnum
|
@@ -204,6 +213,10 @@ class MH(Internet[Data_MH, Schema_MH],
|
204 | 213 | Enum_Option.MESG_ID_OPTION_TYPE: 'mesg_id',
|
205 | 214 | Enum_Option.CGA_Parameters_Request: 'cga_pr',
|
206 | 215 | 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', |
207 | 220 | },
|
208 | 221 | ) # type: DefaultDict[Enum_Option | int, str | tuple[OptionParser, OptionConstructor]]
|
209 | 222 |
|
@@ -945,6 +958,143 @@ def _read_opt_cga_param(self, schema: 'Schema_CGAParametersOption', *,
|
945 | 958 | )
|
946 | 959 | return data
|
947 | 960 |
|
| 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 | + |
948 | 1098 |
|
949 | 1099 |
|
950 | 1100 |
|
@@ -1525,6 +1675,97 @@ def _make_opt_cga_param(self, type: 'Enum_Option', option: 'Optional[Data_CGAPar
|
1525 | 1675 | parameters=param,
|
1526 | 1676 | )
|
1527 | 1677 |
|
| 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 | + |
1528 | 1769 |
|
1529 | 1770 |
|
1530 | 1771 |
|
|
0 commit comments