Source code for pcapkit.const.hip.group
# -*- coding: utf-8 -*-
# pylint: disable=line-too-long,consider-using-f-string
"""Group IDs
===============
.. module:: pcapkit.const.hip.group
This module contains the constant enumeration for **Group IDs**,
which is automatically generated from :class:`pcapkit.vendor.hip.group.Group`.
"""
from typing import TYPE_CHECKING
from aenum import IntEnum
from pcapkit.corekit.enum import EnumRegistry
from pcapkit.utilities.exceptions import EnumValueError
if TYPE_CHECKING:
from typing import Any
__all__ = ['Group']
[docs]
class Group(EnumRegistry, IntEnum):
"""[Group] Group IDs"""
#: Reserved [:rfc:`7401`]
Reserved_0 = 0
#: 384-bit group (DEPRECATED) [:rfc:`5201`]
Group_384_bit_group = 1
#: OAKLEY well known group 1 (DEPRECATED) [:rfc:`5201`]
OAKLEY_well_known_group_1 = 2
#: 1536-bit MODP group [:rfc:`7401`]
Group_1536_bit_MODP_group = 3
#: 3072-bit MODP group [:rfc:`7401`]
Group_3072_bit_MODP_group = 4
#: 6144-bit MODP group (DEPRECATED) [:rfc:`5201`]
Group_6144_bit_MODP_group = 5
#: 8192-bit MODP group (DEPRECATED) [:rfc:`5201`]
Group_8192_bit_MODP_group = 6
#: NIST P-256 [:rfc:`7401`]
NIST_P_256 = 7
#: NIST P-384 [:rfc:`7401`]
NIST_P_384 = 8
#: NIST P-521 [:rfc:`7401`]
NIST_P_521 = 9
#: SECP160R1 [:rfc:`7401`]
SECP160R1 = 10
#: 2048-bit MODP group [:rfc:`7401`]
Group_2048_bit_MODP_group = 11
[docs]
@classmethod
def _validate_value(cls, value: 'Any') -> 'None':
"""Reject ``value`` unless it passes the range check :meth:`_missing_` makes.
Overrides :meth:`~pcapkit.corekit.enum.EnumLookup._validate_value`
with that check and the message it raises, so
:meth:`~pcapkit.corekit.enum.EnumRegistry.register` refuses exactly the
values :meth:`~pcapkit.corekit.enum.EnumLookup.get` refuses, in the
same words (:issue:`1816`).
Args:
value: Value about to be looked up or minted.
Raises:
EnumValueError: If ``value`` fails that check. A
:exc:`ValueError`, so an ``except ValueError`` caller is
unaffected.
"""
if not (isinstance(value, int) and 0 <= value <= 255):
raise EnumValueError('%r is not a valid %s' % (value, cls.__name__))
[docs]
@classmethod
def _missing_(cls, value: 'int') -> 'Group':
"""Lookup function used when value is not found.
Args:
value: Value to get enum item.
"""
if not (isinstance(value, int) and 0 <= value <= 255):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 12 <= value <= 255:
# Unassigned
return cls._unregistered_member(value, 'Unassigned')
return super()._missing_(value)