|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""SSLv2 Handshake Message Type |
| 3 | +================================== |
| 4 | +
|
| 5 | +.. module:: pcapkit.vendor.sslv2.handshake_type |
| 6 | +
|
| 7 | +This module contains the vendor crawler for **SSLv2 Handshake Message Type**, |
| 8 | +which is automatically generating :class:`pcapkit.const.sslv2.handshake_type.HandshakeType`. |
| 9 | +
|
| 10 | +""" |
| 11 | + |
| 12 | +import collections |
| 13 | +import sys |
| 14 | +from typing import TYPE_CHECKING |
| 15 | + |
| 16 | +from pcapkit.vendor.default import Vendor |
| 17 | + |
| 18 | +if TYPE_CHECKING: |
| 19 | + from collections import Counter |
| 20 | + |
| 21 | +__all__ = ['HandshakeType'] |
| 22 | + |
| 23 | +############################################################################### |
| 24 | +# NOTE: this crawler does not crawl. Its source is the expired Netscape SSLv2 |
| 25 | +# draft, draft-hickman-netscape-ssl-00, which is not an IANA (or any other) |
| 26 | +# live registry a crawler could re-fetch -- there is nothing upstream of this |
| 27 | +# module to go stale against. Per the const-vendor-pairing convention, a |
| 28 | +# hand-maintained registry still gets a crawler, reading |
| 29 | +# :data:`~pcapkit.vendor.sslv2.handshake_type.DATA` instead of fetching a URL |
| 30 | +# -- the same shape as :mod:`pcapkit.vendor.linux.arphrd`, |
| 31 | +# :mod:`pcapkit.vendor.ipx.packet` and :mod:`pcapkit.vendor.ipx.socket`. |
| 32 | +############################################################################### |
| 33 | + |
| 34 | +#: SSLv2 handshake message type registry, transcribed from |
| 35 | +#: draft-hickman-netscape-ssl-00 for the complete, closed set of ``MSG-*`` |
| 36 | +#: codes the draft defines. |
| 37 | +#: |
| 38 | +#: Maps a handshake message type to the enumeration name it takes and the |
| 39 | +#: ``MSG-*`` constant the comment above it renders. Names go through |
| 40 | +#: :meth:`~Vendor.rename`, so the generated member is the |
| 41 | +#: :meth:`~Vendor.safe_name` of the first element. |
| 42 | +DATA = { |
| 43 | + 0: ('ERROR', '``MSG-ERROR``'), |
| 44 | + 1: ('CLIENT_HELLO', '``MSG-CLIENT-HELLO``'), |
| 45 | + 2: ('CLIENT_MASTER_KEY', '``MSG-CLIENT-MASTER-KEY``'), |
| 46 | + 3: ('CLIENT_FINISHED', '``MSG-CLIENT-FINISHED``'), |
| 47 | + 4: ('SERVER_HELLO', '``MSG-SERVER-HELLO``'), |
| 48 | + 5: ('SERVER_VERIFY', '``MSG-SERVER-VERIFY``'), |
| 49 | + 6: ('SERVER_FINISHED', '``MSG-SERVER-FINISHED``'), |
| 50 | + 7: ('REQUEST_CERTIFICATE', '``MSG-REQUEST-CERTIFICATE``'), |
| 51 | + 8: ('CLIENT_CERTIFICATE', '``MSG-CLIENT-CERTIFICATE``'), |
| 52 | +} # type: dict[int, tuple[str, str]] |
| 53 | + |
| 54 | + |
| 55 | +class HandshakeType(Vendor): |
| 56 | + """SSLv2 Handshake Message Type""" |
| 57 | + |
| 58 | + #: Value limit checker. |
| 59 | + FLAG = 'isinstance(value, int) and 0x00 <= value <= 0xFF' |
| 60 | + |
| 61 | + def request(self) -> 'dict[int, tuple[str, str]]': # type: ignore[override] # pylint: disable=arguments-differ |
| 62 | + """Fetch registry data. |
| 63 | +
|
| 64 | + Returns: |
| 65 | + Registry data (:data:`~pcapkit.vendor.sslv2.handshake_type.DATA`). |
| 66 | +
|
| 67 | + """ |
| 68 | + return DATA |
| 69 | + |
| 70 | + def count(self, data: 'dict[int, tuple[str, str]]') -> 'Counter[str]': # type: ignore[override] |
| 71 | + """Count field records. |
| 72 | +
|
| 73 | + Args: |
| 74 | + data: Registry data. |
| 75 | +
|
| 76 | + Returns: |
| 77 | + Field recordings. |
| 78 | +
|
| 79 | + """ |
| 80 | + return collections.Counter(self.safe_name(name) for name, _ in data.values()) |
| 81 | + |
| 82 | + def process(self, data: 'dict[int, tuple[str, str]]') -> 'tuple[list[str], list[str]]': # type: ignore[override] |
| 83 | + """Process registry data. |
| 84 | +
|
| 85 | + Args: |
| 86 | + data: Registry data. |
| 87 | +
|
| 88 | + Returns: |
| 89 | + Enumeration fields and missing fields. |
| 90 | +
|
| 91 | + """ |
| 92 | + enum = [] # type: list[str] |
| 93 | + miss = [ |
| 94 | + "return cls._unregistered_member(value, 'Unassigned')", |
| 95 | + ] |
| 96 | + |
| 97 | + for code, (name, desc) in data.items(): |
| 98 | + pval = str(code) |
| 99 | + renm = self.rename(name, pval) |
| 100 | + |
| 101 | + enum.append(f'#: {self.wrap_comment(desc)}\n {renm} = {pval}') |
| 102 | + return enum, miss |
| 103 | + |
| 104 | + |
| 105 | +if __name__ == '__main__': |
| 106 | + sys.exit(HandshakeType()) # type: ignore[arg-type] |
0 commit comments