diff --git a/pytcp/protocols/dhcp4/options/dhcp4_option__message_type.py b/pytcp/protocols/dhcp4/options/dhcp4_option__message_type.py new file mode 100644 index 00000000..0347e846 --- /dev/null +++ b/pytcp/protocols/dhcp4/options/dhcp4_option__message_type.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 + +################################################################################ +## ## +## PyTCP - Python TCP/IP stack ## +## Copyright (C) 2020-present Sebastian Majewski ## +## ## +## This program is free software: you can redistribute it and/or modify ## +## it under the terms of the GNU General Public License as published by ## +## the Free Software Foundation, either version 3 of the License, or ## +## (at your option) any later version. ## +## ## +## This program is distributed in the hope that it will be useful, ## +## but WITHOUT ANY WARRANTY; without even the implied warranty of ## +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## +## GNU General Public License for more details. ## +## ## +## You should have received a copy of the GNU General Public License ## +## along with this program. If not, see . ## +## ## +## Author's email: ccie18643@gmail.com ## +## Github repository: https://github.com/ccie18643/PyTCP ## +## ## +################################################################################ + + +""" +Module contains the DHCPv4 Message Type option support code. + +pytcp/protocols/dhcp4/options/dhcp4_option__message_type.py + +ver 3.0.2 +""" + + +from __future__ import annotations + +""" +import struct +from dataclasses import dataclass, field +from typing import override + +from pytcp.lib.int_checks import is_uint16 +from pytcp.protocols.tcp.options.tcp_option import ( + TCP__OPTION__LEN, + TcpOption, + TcpOptionType, +) +from pytcp.protocols.tcp.tcp__errors import TcpIntegrityError +""" + +# The DHCPv4 Message Type option [RFC 2132]. + +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +# | Type = 1 | Length = 1 | Value | +# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + +DHCP4__OPTION__MESSAGE_TYPE__LEN = 4 + +''' +@dataclass(frozen=True, kw_only=True) +class TcpOptionMss(TcpOption): + """ + The TCP Mss (Maximum Segment Size) option support class. + """ + + type: TcpOptionType = field( + repr=False, + init=False, + default=TcpOptionType.MSS, + ) + len: int = field( + repr=False, + init=False, + default=TCP__OPTION_MSS__LEN, + ) + + mss: int + + @override + def __post_init__(self) -> None: + """ + Validate the TCP Mss option fields. + """ + + assert is_uint16(self.mss), ( + f"The 'mss' field must be a 16-bit unsigned integer. " + f"Got: {self.mss}" + ) + + @override + def __str__(self) -> str: + """ + Get the TCP Mss option log string. + """ + + return f"mss {self.mss}" + + @override + def __bytes__(self) -> bytes: + """ + Get the TCP Mss option as bytes. + """ + + return struct.pack( + "! BB H", + int(self.type), + self.len, + self.mss, + ) + + @staticmethod + def _validate_integrity(_bytes: bytes, /) -> None: + """ + Validate the TCP Mss option integrity before parsing it. + """ + + if (value := _bytes[1]) != TCP__OPTION_MSS__LEN: + raise TcpIntegrityError( + f"The TCP Mss option length must be {TCP__OPTION_MSS__LEN} " + f"bytes. Got: {value!r}" + ) + + if (value := _bytes[1]) > len(_bytes): + raise TcpIntegrityError( + "The TCP Mss option length must be less than or equal to " + f"the length of provided bytes ({len(_bytes)}). Got: {value!r}" + ) + + @override + @staticmethod + def from_bytes(_bytes: bytes, /) -> TcpOptionMss: + """ + Initialize the TCP Mss option from bytes. + """ + + assert (value := len(_bytes)) >= TCP__OPTION__LEN, ( + f"The minimum length of the TCP Mss option must be " + f"{TCP__OPTION__LEN} bytes. Got: {value!r}" + ) + + assert (value := _bytes[0]) == int(TcpOptionType.MSS), ( + f"The TCP Mss option type must be {TcpOptionType.MSS!r}. " + f"Got: {TcpOptionType.from_int(value)!r}" + ) + + TcpOptionMss._validate_integrity(_bytes) + + return TcpOptionMss(mss=int.from_bytes(_bytes[2:4])) +''' diff --git a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option.py b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option.py index be2b36b2..97b243f8 100644 --- a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option.py +++ b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option.py @@ -39,8 +39,8 @@ from pytcp.lib.proto_option import ProtoOption, ProtoOptionType -ICMP6__ND_OPTION__STRUCT = "! BB" -ICMP6__ND_OPTION__LEN = 2 +ICMP6__ND__OPTION__STRUCT = "! BB" +ICMP6__ND__OPTION__LEN = 2 class Icmp6NdOptionType(ProtoOptionType): diff --git a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__pi.py b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__pi.py index ca42c3f6..513cc99c 100644 --- a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__pi.py +++ b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__pi.py @@ -43,7 +43,7 @@ from pytcp.lib.net_addr import Ip6Address, Ip6Mask, Ip6Network from pytcp.protocols.icmp6.icmp6__errors import Icmp6IntegrityError from pytcp.protocols.icmp6.message.nd.option.icmp6_nd_option import ( - ICMP6__ND_OPTION__LEN, + ICMP6__ND__OPTION__LEN, Icmp6NdOption, Icmp6NdOptionType, ) @@ -68,8 +68,8 @@ # | | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -ICMP6__ND_OPTION_PI__LEN = 32 -ICMP6__ND_OPTION_PI__STRUCT = "! BB BB L L L 16s" +ICMP6__ND__OPTION__PI__LEN = 32 +ICMP6__ND__OPTION__PI__STRUCT = "! BB BB L L L 16s" @dataclass(frozen=True, kw_only=True) @@ -100,7 +100,7 @@ class Icmp6NdOptionPi(Icmp6NdOption): len: int = field( repr=False, init=False, - default=ICMP6__ND_OPTION_PI__LEN, + default=ICMP6__ND__OPTION__PI__LEN, ) flag_l: bool = False @@ -168,7 +168,7 @@ def __bytes__(self) -> bytes: """ return struct.pack( - ICMP6__ND_OPTION_PI__STRUCT, + ICMP6__ND__OPTION__PI__STRUCT, int(self.type), self.len >> 3, len(self.prefix.mask), @@ -188,9 +188,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the ICMPv6 ND Pi option integrity before parsing it. """ - if (value := _bytes[1] << 3) != ICMP6__ND_OPTION_PI__LEN: + if (value := _bytes[1] << 3) != ICMP6__ND__OPTION__PI__LEN: raise Icmp6IntegrityError( - f"The ICMPv6 ND Pi option length must be {ICMP6__ND_OPTION_PI__LEN} " + f"The ICMPv6 ND Pi option length must be {ICMP6__ND__OPTION__PI__LEN} " f"bytes. Got: {value!r}" ) @@ -207,9 +207,9 @@ def from_bytes(_bytes: bytes, /) -> Icmp6NdOptionPi: Initialize the ICMPv6 ND Pi option from bytes. """ - assert (value := len(_bytes)) >= ICMP6__ND_OPTION__LEN, ( + assert (value := len(_bytes)) >= ICMP6__ND__OPTION__LEN, ( f"The minimum length of the ICMPv6 ND Pi option must be " - f"{ICMP6__ND_OPTION__LEN} bytes. Got: {value!r}" + f"{ICMP6__ND__OPTION__LEN} bytes. Got: {value!r}" ) assert (value := _bytes[0]) == int(Icmp6NdOptionType.PI), ( @@ -229,7 +229,7 @@ def from_bytes(_bytes: bytes, /) -> Icmp6NdOptionPi: _, prefix, ) = struct.unpack( - ICMP6__ND_OPTION_PI__STRUCT, _bytes[:ICMP6__ND_OPTION_PI__LEN] + ICMP6__ND__OPTION__PI__STRUCT, _bytes[:ICMP6__ND__OPTION__PI__LEN] ) return Icmp6NdOptionPi( diff --git a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__slla.py b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__slla.py index 51206396..fb375db6 100644 --- a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__slla.py +++ b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__slla.py @@ -42,7 +42,7 @@ from pytcp.lib.net_addr import MacAddress from pytcp.protocols.icmp6.icmp6__errors import Icmp6IntegrityError from pytcp.protocols.icmp6.message.nd.option.icmp6_nd_option import ( - ICMP6__ND_OPTION__LEN, + ICMP6__ND__OPTION__LEN, Icmp6NdOption, Icmp6NdOptionType, ) @@ -55,8 +55,8 @@ # > MAC Address | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -ICMP6__ND_OPTION_SLLA__LEN = 8 -ICMP6__ND_OPTION_SLLA__STRUCT = "! BB 6s" +ICMP6__ND__OPTION__SLLA__LEN = 8 +ICMP6__ND__OPTION__SLLA__STRUCT = "! BB 6s" @dataclass(frozen=True, kw_only=True) @@ -73,7 +73,7 @@ class Icmp6NdOptionSlla(Icmp6NdOption): len: int = field( repr=False, init=False, - default=ICMP6__ND_OPTION_SLLA__LEN, + default=ICMP6__ND__OPTION__SLLA__LEN, ) slla: MacAddress @@ -103,7 +103,7 @@ def __bytes__(self) -> bytes: """ return struct.pack( - ICMP6__ND_OPTION_SLLA__STRUCT, + ICMP6__ND__OPTION__SLLA__STRUCT, int(self.type), self.len >> 3, bytes(self.slla), @@ -115,9 +115,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the ICMPv6 ND Slla option integrity before parsing it. """ - if (value := _bytes[1] << 3) != ICMP6__ND_OPTION_SLLA__LEN: + if (value := _bytes[1] << 3) != ICMP6__ND__OPTION__SLLA__LEN: raise Icmp6IntegrityError( - f"The ICMPv6 ND Slla option length must be {ICMP6__ND_OPTION_SLLA__LEN} " + f"The ICMPv6 ND Slla option length must be {ICMP6__ND__OPTION__SLLA__LEN} " f"bytes. Got: {value!r}" ) @@ -134,9 +134,9 @@ def from_bytes(_bytes: bytes, /) -> Icmp6NdOptionSlla: Initialize the ICMPv6 ND Slla option from bytes. """ - assert (value := len(_bytes)) >= ICMP6__ND_OPTION__LEN, ( + assert (value := len(_bytes)) >= ICMP6__ND__OPTION__LEN, ( f"The minimum length of the ICMPv6 ND Slla option must be " - f"{ICMP6__ND_OPTION__LEN} bytes. Got: {value!r}" + f"{ICMP6__ND__OPTION__LEN} bytes. Got: {value!r}" ) assert (value := _bytes[0]) == int(Icmp6NdOptionType.SLLA), ( diff --git a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__tlla.py b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__tlla.py index eeb7ea82..f98e314f 100644 --- a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__tlla.py +++ b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__tlla.py @@ -42,7 +42,7 @@ from pytcp.lib.net_addr import MacAddress from pytcp.protocols.icmp6.icmp6__errors import Icmp6IntegrityError from pytcp.protocols.icmp6.message.nd.option.icmp6_nd_option import ( - ICMP6__ND_OPTION__LEN, + ICMP6__ND__OPTION__LEN, Icmp6NdOption, Icmp6NdOptionType, ) @@ -55,8 +55,8 @@ # > MAC Address | # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -ICMP6__ND_OPTION_TLLA__LEN = 8 -ICMP6__ND_OPTION_TLLA__STRUCT = "! BB 6s" +ICMP6__ND__OPTION__TLLA__LEN = 8 +ICMP6__ND__OPTION__TLLA__STRUCT = "! BB 6s" @dataclass(frozen=True, kw_only=True) @@ -73,7 +73,7 @@ class Icmp6NdOptionTlla(Icmp6NdOption): len: int = field( repr=False, init=False, - default=ICMP6__ND_OPTION_TLLA__LEN, + default=ICMP6__ND__OPTION__TLLA__LEN, ) tlla: MacAddress @@ -103,7 +103,7 @@ def __bytes__(self) -> bytes: """ return struct.pack( - ICMP6__ND_OPTION_TLLA__STRUCT, + ICMP6__ND__OPTION__TLLA__STRUCT, int(self.type), self.len >> 3, bytes(self.tlla), @@ -115,9 +115,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the integrity of the ICMPv6 ND Tlla option before parsing it. """ - if (value := _bytes[1] << 3) != ICMP6__ND_OPTION_TLLA__LEN: + if (value := _bytes[1] << 3) != ICMP6__ND__OPTION__TLLA__LEN: raise Icmp6IntegrityError( - f"The ICMPv6 ND Tlla option length must be {ICMP6__ND_OPTION_TLLA__LEN} " + f"The ICMPv6 ND Tlla option length must be {ICMP6__ND__OPTION__TLLA__LEN} " f"bytes. Got: {value!r}" ) @@ -134,9 +134,9 @@ def from_bytes(_bytes: bytes, /) -> Icmp6NdOptionTlla: Initialize the ICMPv6 ND Tlla option from bytes. """ - assert (value := len(_bytes)) >= ICMP6__ND_OPTION__LEN, ( + assert (value := len(_bytes)) >= ICMP6__ND__OPTION__LEN, ( f"The minimum length of the ICMPv6 ND Tlla option must be " - f"{ICMP6__ND_OPTION__LEN} bytes. Got: {value!r}" + f"{ICMP6__ND__OPTION__LEN} bytes. Got: {value!r}" ) assert (value := _bytes[0]) == int(Icmp6NdOptionType.TLLA), ( diff --git a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__unknown.py b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__unknown.py index 680098f2..6b2f2f83 100644 --- a/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__unknown.py +++ b/pytcp/protocols/icmp6/message/nd/option/icmp6_nd_option__unknown.py @@ -42,8 +42,8 @@ from pytcp.lib.int_checks import is_8_byte_alligned, is_uint8 from pytcp.protocols.icmp6.icmp6__errors import Icmp6IntegrityError from pytcp.protocols.icmp6.message.nd.option.icmp6_nd_option import ( - ICMP6__ND_OPTION__LEN, - ICMP6__ND_OPTION__STRUCT, + ICMP6__ND__OPTION__LEN, + ICMP6__ND__OPTION__STRUCT, Icmp6NdOption, Icmp6NdOptionType, ) @@ -63,7 +63,7 @@ class Icmp6NdOptionUnknown(Icmp6NdOption): len: int = field( repr=True, init=True, - default=ICMP6__ND_OPTION__LEN, + default=ICMP6__ND__OPTION__LEN, ) data: bytes @@ -93,9 +93,9 @@ def __post_init__(self) -> None: self.len ), f"The 'len' field must be 8-byte aligned. Got: {self.len!r}" - assert self.len == ICMP6__ND_OPTION__LEN + len(self.data), ( + assert self.len == ICMP6__ND__OPTION__LEN + len(self.data), ( "The 'len' field must reflect the length of the 'data' field. " - f"Got: {self.len!r} != {ICMP6__ND_OPTION__LEN + len(self.data)!r}" + f"Got: {self.len!r} != {ICMP6__ND__OPTION__LEN + len(self.data)!r}" ) @override @@ -114,7 +114,7 @@ def __bytes__(self) -> bytes: return ( struct.pack( - ICMP6__ND_OPTION__STRUCT, + ICMP6__ND__OPTION__STRUCT, int(self.type), self.len >> 3, ) @@ -140,9 +140,9 @@ def from_bytes(_bytes: bytes, /) -> Icmp6NdOptionUnknown: Initialize the unknown ICMPv6 option from bytes. """ - assert (value := len(_bytes)) >= ICMP6__ND_OPTION__LEN, ( + assert (value := len(_bytes)) >= ICMP6__ND__OPTION__LEN, ( f"The minimum length of the unknown ICMPv6 ND option must be " - f"{ICMP6__ND_OPTION__LEN} bytes. Got: {value!r}" + f"{ICMP6__ND__OPTION__LEN} bytes. Got: {value!r}" ) assert ( @@ -157,5 +157,5 @@ def from_bytes(_bytes: bytes, /) -> Icmp6NdOptionUnknown: return Icmp6NdOptionUnknown( type=Icmp6NdOptionType(_bytes[0]), len=_bytes[1] << 3, - data=_bytes[ICMP6__ND_OPTION__LEN : _bytes[1] << 3], + data=_bytes[ICMP6__ND__OPTION__LEN : _bytes[1] << 3], ) diff --git a/pytcp/protocols/ip4/options/ip4_option__eol.py b/pytcp/protocols/ip4/options/ip4_option__eol.py index 908239b7..3c3fa04e 100644 --- a/pytcp/protocols/ip4/options/ip4_option__eol.py +++ b/pytcp/protocols/ip4/options/ip4_option__eol.py @@ -47,7 +47,7 @@ # +-+-+-+-+-+-+-+-+ -IP4__OPTION_EOL__LEN = 1 +IP4__OPTION__EOL__LEN = 1 @dataclass(frozen=True, kw_only=True) @@ -64,7 +64,7 @@ class Ip4OptionEol(Ip4Option): len: int = field( repr=False, init=False, - default=IP4__OPTION_EOL__LEN, + default=IP4__OPTION__EOL__LEN, ) @override @@ -96,9 +96,9 @@ def from_bytes(_bytes: bytes, /) -> Ip4OptionEol: Initialize the IPv4 Eol option from bytes. """ - assert (value := len(_bytes)) >= IP4__OPTION_EOL__LEN, ( + assert (value := len(_bytes)) >= IP4__OPTION__EOL__LEN, ( f"The minimum length of the IPv4 Eol option must be " - f"{IP4__OPTION_EOL__LEN} byte. Got: {value!r}" + f"{IP4__OPTION__EOL__LEN} byte. Got: {value!r}" ) assert (value := _bytes[0]) == int(Ip4OptionType.EOL), ( diff --git a/pytcp/protocols/ip4/options/ip4_option__nop.py b/pytcp/protocols/ip4/options/ip4_option__nop.py index b1bb934f..faa1e64c 100644 --- a/pytcp/protocols/ip4/options/ip4_option__nop.py +++ b/pytcp/protocols/ip4/options/ip4_option__nop.py @@ -47,7 +47,7 @@ # +-+-+-+-+-+-+-+-+ -IP4__OPTION_NOP__LEN = 1 +IP4__OPTION__NOP__LEN = 1 @dataclass(frozen=True, kw_only=True) @@ -64,7 +64,7 @@ class Ip4OptionNop(Ip4Option): len: int = field( repr=False, init=False, - default=IP4__OPTION_NOP__LEN, + default=IP4__OPTION__NOP__LEN, ) @override @@ -96,9 +96,9 @@ def from_bytes(_bytes: bytes, /) -> Ip4OptionNop: Initialize the IPv4 Nop option from bytes. """ - assert (value := len(_bytes)) >= IP4__OPTION_NOP__LEN, ( + assert (value := len(_bytes)) >= IP4__OPTION__NOP__LEN, ( f"The minimum length of the IPv4 Nop option must be " - f"{IP4__OPTION_NOP__LEN} byte. Got: {value!r}" + f"{IP4__OPTION__NOP__LEN} byte. Got: {value!r}" ) assert (value := _bytes[0]) == int(Ip4OptionType.NOP), ( diff --git a/pytcp/protocols/ip4/options/ip4_options.py b/pytcp/protocols/ip4/options/ip4_options.py index 3d49c058..962b622f 100644 --- a/pytcp/protocols/ip4/options/ip4_options.py +++ b/pytcp/protocols/ip4/options/ip4_options.py @@ -44,7 +44,7 @@ from pytcp.protocols.ip4.options.ip4_option import Ip4Option, Ip4OptionType from pytcp.protocols.ip4.options.ip4_option__eol import Ip4OptionEol from pytcp.protocols.ip4.options.ip4_option__nop import ( - IP4__OPTION_NOP__LEN, + IP4__OPTION__NOP__LEN, Ip4OptionNop, ) from pytcp.protocols.ip4.options.ip4_option__unknown import Ip4OptionUnknown @@ -74,7 +74,7 @@ def validate_integrity( break if frame[offset] == int(Ip4OptionType.NOP): - offset += IP4__OPTION_NOP__LEN + offset += IP4__OPTION__NOP__LEN continue if (value := frame[offset + 1]) < 2: diff --git a/pytcp/protocols/tcp/options/tcp_option__eol.py b/pytcp/protocols/tcp/options/tcp_option__eol.py index be1fa800..1fbd5969 100644 --- a/pytcp/protocols/tcp/options/tcp_option__eol.py +++ b/pytcp/protocols/tcp/options/tcp_option__eol.py @@ -47,7 +47,7 @@ # +-+-+-+-+-+-+-+-+ -TCP__OPTION_EOL__LEN = 1 +TCP__OPTION__EOL__LEN = 1 @dataclass(frozen=True, kw_only=True) @@ -64,7 +64,7 @@ class TcpOptionEol(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_EOL__LEN, + default=TCP__OPTION__EOL__LEN, ) @override @@ -96,9 +96,9 @@ def from_bytes(_bytes: bytes, /) -> TcpOptionEol: Initialize the TCP Eol option from bytes. """ - assert (value := len(_bytes)) >= TCP__OPTION_EOL__LEN, ( + assert (value := len(_bytes)) >= TCP__OPTION__EOL__LEN, ( f"The minimum length of the TCP Eol option must be " - f"{TCP__OPTION_EOL__LEN} byte. Got: {value!r}" + f"{TCP__OPTION__EOL__LEN} byte. Got: {value!r}" ) assert (value := _bytes[0]) == int(TcpOptionType.EOL), ( diff --git a/pytcp/protocols/tcp/options/tcp_option__mss.py b/pytcp/protocols/tcp/options/tcp_option__mss.py index 0dfa1f4a..4f8b5554 100644 --- a/pytcp/protocols/tcp/options/tcp_option__mss.py +++ b/pytcp/protocols/tcp/options/tcp_option__mss.py @@ -54,7 +54,7 @@ # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -TCP__OPTION_MSS__LEN = 4 +TCP__OPTION__MSS__LEN = 4 @dataclass(frozen=True, kw_only=True) @@ -71,7 +71,7 @@ class TcpOptionMss(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_MSS__LEN, + default=TCP__OPTION__MSS__LEN, ) mss: int @@ -114,9 +114,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the TCP Mss option integrity before parsing it. """ - if (value := _bytes[1]) != TCP__OPTION_MSS__LEN: + if (value := _bytes[1]) != TCP__OPTION__MSS__LEN: raise TcpIntegrityError( - f"The TCP Mss option length must be {TCP__OPTION_MSS__LEN} " + f"The TCP Mss option length must be {TCP__OPTION__MSS__LEN} " f"bytes. Got: {value!r}" ) diff --git a/pytcp/protocols/tcp/options/tcp_option__nop.py b/pytcp/protocols/tcp/options/tcp_option__nop.py index 21e9954e..e0adbf2c 100644 --- a/pytcp/protocols/tcp/options/tcp_option__nop.py +++ b/pytcp/protocols/tcp/options/tcp_option__nop.py @@ -47,7 +47,7 @@ # +-+-+-+-+-+-+-+-+ -TCP__OPTION_NOP__LEN = 1 +TCP__OPTION__NOP__LEN = 1 @dataclass(frozen=True, kw_only=True) @@ -64,7 +64,7 @@ class TcpOptionNop(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_NOP__LEN, + default=TCP__OPTION__NOP__LEN, ) @override @@ -96,9 +96,9 @@ def from_bytes(_bytes: bytes, /) -> TcpOptionNop: Initialize the TCP Nop option from bytes. """ - assert (value := len(_bytes)) >= TCP__OPTION_NOP__LEN, ( + assert (value := len(_bytes)) >= TCP__OPTION__NOP__LEN, ( f"The minimum length of the TCP Nop option must be " - f"{TCP__OPTION_NOP__LEN} byte. Got: {value!r}" + f"{TCP__OPTION__NOP__LEN} byte. Got: {value!r}" ) assert (value := _bytes[0]) == int(TcpOptionType.NOP), ( diff --git a/pytcp/protocols/tcp/options/tcp_option__sack.py b/pytcp/protocols/tcp/options/tcp_option__sack.py index b08cdb59..3b6c9656 100644 --- a/pytcp/protocols/tcp/options/tcp_option__sack.py +++ b/pytcp/protocols/tcp/options/tcp_option__sack.py @@ -63,9 +63,9 @@ # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -TCP__OPTION_SACK__LEN = 2 -TCP__OPTION_SACK__BLOCK_LEN = 8 -TCP__OPTION_SACK__MAX_BLOCK_NUM = 4 +TCP__OPTION__SACK__LEN = 2 +TCP__OPTION__SACK__BLOCK_LEN = 8 +TCP__OPTION__SACK__MAX_BLOCK_NUM = 4 @dataclass(frozen=True, kw_only=False) @@ -82,7 +82,7 @@ def __len__(self) -> int: Get the TCP Sack block length. """ - return TCP__OPTION_SACK__BLOCK_LEN + return TCP__OPTION__SACK__BLOCK_LEN def __bytes__(self) -> bytes: """ @@ -117,7 +117,7 @@ class TcpOptionSack(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_SACK__LEN, + default=TCP__OPTION__SACK__LEN, ) blocks: list[TcpSackBlock] @@ -128,8 +128,8 @@ def __post_init__(self) -> None: Validate the TCP Sack option fields. """ - assert len(self.blocks) <= TCP__OPTION_SACK__MAX_BLOCK_NUM, ( - f"The 'blocks' field must have at most {TCP__OPTION_SACK__MAX_BLOCK_NUM} " + assert len(self.blocks) <= TCP__OPTION__SACK__MAX_BLOCK_NUM, ( + f"The 'blocks' field must have at most {TCP__OPTION__SACK__MAX_BLOCK_NUM} " f"elements. Got: {len(self.blocks)}" ) @@ -137,8 +137,8 @@ def __post_init__(self) -> None: object.__setattr__( self, "len", - TCP__OPTION_SACK__LEN - + TCP__OPTION_SACK__BLOCK_LEN * len(self.blocks), + TCP__OPTION__SACK__LEN + + TCP__OPTION__SACK__BLOCK_LEN * len(self.blocks), ) @override @@ -156,7 +156,7 @@ def __bytes__(self) -> bytes: """ return struct.pack( - f"! BB {TCP__OPTION_SACK__BLOCK_LEN * len(self.blocks)}s", + f"! BB {TCP__OPTION__SACK__BLOCK_LEN * len(self.blocks)}s", int(self.type), self.len, b"".join([bytes(block) for block in self.blocks]), @@ -175,11 +175,11 @@ def _validate_integrity(_bytes: bytes, /) -> None: ) if ( - value := _bytes[1] - TCP__OPTION_SACK__LEN - ) % TCP__OPTION_SACK__BLOCK_LEN: + value := _bytes[1] - TCP__OPTION__SACK__LEN + ) % TCP__OPTION__SACK__BLOCK_LEN: raise TcpIntegrityError( "The TCP Sack option blocks length must be a multiple of " - f"{TCP__OPTION_SACK__BLOCK_LEN}. Got: {value!r}" + f"{TCP__OPTION__SACK__BLOCK_LEN}. Got: {value!r}" ) @override @@ -206,21 +206,21 @@ def from_bytes(_bytes: bytes, /) -> TcpOptionSack: TcpSackBlock( left=int.from_bytes( _bytes[ - offset : offset + TCP__OPTION_SACK__BLOCK_LEN // 2 + offset : offset + TCP__OPTION__SACK__BLOCK_LEN // 2 ] ), right=int.from_bytes( _bytes[ offset - + TCP__OPTION_SACK__BLOCK_LEN // 2 : offset - + TCP__OPTION_SACK__BLOCK_LEN + + TCP__OPTION__SACK__BLOCK_LEN // 2 : offset + + TCP__OPTION__SACK__BLOCK_LEN ] ), ) for offset in range( - TCP__OPTION_SACK__LEN, - _bytes[1] - TCP__OPTION_SACK__LEN, - TCP__OPTION_SACK__BLOCK_LEN, + TCP__OPTION__SACK__LEN, + _bytes[1] - TCP__OPTION__SACK__LEN, + TCP__OPTION__SACK__BLOCK_LEN, ) ] ) diff --git a/pytcp/protocols/tcp/options/tcp_option__sackperm.py b/pytcp/protocols/tcp/options/tcp_option__sackperm.py index 57c699be..4feec05e 100644 --- a/pytcp/protocols/tcp/options/tcp_option__sackperm.py +++ b/pytcp/protocols/tcp/options/tcp_option__sackperm.py @@ -53,7 +53,7 @@ # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -TCP__OPTION_SACKPERM__LEN = 2 +TCP__OPTION__SACKPERM__LEN = 2 @dataclass(frozen=True, kw_only=True) @@ -70,7 +70,7 @@ class TcpOptionSackperm(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_SACKPERM__LEN, + default=TCP__OPTION__SACKPERM__LEN, ) @override @@ -105,9 +105,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the TCP Sackperm option integrity before parsing it. """ - if (value := _bytes[1]) != TCP__OPTION_SACKPERM__LEN: + if (value := _bytes[1]) != TCP__OPTION__SACKPERM__LEN: raise TcpIntegrityError( - f"The TCP Sackperm option length must be {TCP__OPTION_SACKPERM__LEN} " + f"The TCP Sackperm option length must be {TCP__OPTION__SACKPERM__LEN} " f"bytes. Got: {value!r}" ) diff --git a/pytcp/protocols/tcp/options/tcp_option__timestamps.py b/pytcp/protocols/tcp/options/tcp_option__timestamps.py index 8be0238b..1fe481e8 100644 --- a/pytcp/protocols/tcp/options/tcp_option__timestamps.py +++ b/pytcp/protocols/tcp/options/tcp_option__timestamps.py @@ -58,7 +58,7 @@ # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -TCP__OPTION_TIMESTAMPS__LEN = 10 +TCP__OPTION__TIMESTAMPS__LEN = 10 @dataclass @@ -85,7 +85,7 @@ class TcpOptionTimestamps(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_TIMESTAMPS__LEN, + default=TCP__OPTION__TIMESTAMPS__LEN, ) tsval: int @@ -135,9 +135,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the TCP Timestamps option integrity before parsing it. """ - if (value := _bytes[1]) != TCP__OPTION_TIMESTAMPS__LEN: + if (value := _bytes[1]) != TCP__OPTION__TIMESTAMPS__LEN: raise TcpIntegrityError( - f"The TCP Timestamps option length must be {TCP__OPTION_TIMESTAMPS__LEN} " + f"The TCP Timestamps option length must be {TCP__OPTION__TIMESTAMPS__LEN} " f"bytes. Got: {value!r}" ) diff --git a/pytcp/protocols/tcp/options/tcp_option__wscale.py b/pytcp/protocols/tcp/options/tcp_option__wscale.py index 8f1d5f03..b6831a5e 100644 --- a/pytcp/protocols/tcp/options/tcp_option__wscale.py +++ b/pytcp/protocols/tcp/options/tcp_option__wscale.py @@ -54,8 +54,8 @@ # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -TCP__OPTION_WSCALE__LEN = 3 -TCP__OPTION_WSCALE__MAX_VALUE = 14 +TCP__OPTION__WSCALE__LEN = 3 +TCP__OPTION__WSCALE__MAX_VALUE = 14 @dataclass(frozen=True, kw_only=True) @@ -72,7 +72,7 @@ class TcpOptionWscale(TcpOption): len: int = field( repr=False, init=False, - default=TCP__OPTION_WSCALE__LEN, + default=TCP__OPTION__WSCALE__LEN, ) wscale: int @@ -85,10 +85,10 @@ def __post_init__(self) -> None: assert ( is_uint8(self.wscale) - and self.wscale <= TCP__OPTION_WSCALE__MAX_VALUE + and self.wscale <= TCP__OPTION__WSCALE__MAX_VALUE ), ( f"The 'wscale' field must be a 8-bit unsigned integer less than " - f"or equal to {TCP__OPTION_WSCALE__MAX_VALUE}. Got: {self.wscale}" + f"or equal to {TCP__OPTION__WSCALE__MAX_VALUE}. Got: {self.wscale}" ) @override @@ -118,9 +118,9 @@ def _validate_integrity(_bytes: bytes, /) -> None: Validate the TCP Wscale option integrity before parsing it. """ - if (value := _bytes[1]) != TCP__OPTION_WSCALE__LEN: + if (value := _bytes[1]) != TCP__OPTION__WSCALE__LEN: raise TcpIntegrityError( - f"The TCP Wscale option length must be {TCP__OPTION_WSCALE__LEN} " + f"The TCP Wscale option length must be {TCP__OPTION__WSCALE__LEN} " f"bytes. Got: {value!r}" ) @@ -151,6 +151,6 @@ def from_bytes(_bytes: bytes, /) -> TcpOptionWscale: # Correct the received Wscale option value to maximum allowed # if it exceeds the limit. - wscale = min(_bytes[2], TCP__OPTION_WSCALE__MAX_VALUE) + wscale = min(_bytes[2], TCP__OPTION__WSCALE__MAX_VALUE) return TcpOptionWscale(wscale=wscale) diff --git a/pytcp/protocols/tcp/options/tcp_options.py b/pytcp/protocols/tcp/options/tcp_options.py index 2ad8eac9..3391336b 100644 --- a/pytcp/protocols/tcp/options/tcp_options.py +++ b/pytcp/protocols/tcp/options/tcp_options.py @@ -44,7 +44,7 @@ from pytcp.protocols.tcp.options.tcp_option__eol import TcpOptionEol from pytcp.protocols.tcp.options.tcp_option__mss import TcpOptionMss from pytcp.protocols.tcp.options.tcp_option__nop import ( - TCP__OPTION_NOP__LEN, + TCP__OPTION__NOP__LEN, TcpOptionNop, ) from pytcp.protocols.tcp.options.tcp_option__sack import ( @@ -146,7 +146,7 @@ def validate_integrity( break if frame[offset] == int(TcpOptionType.NOP): - offset += TCP__OPTION_NOP__LEN + offset += TCP__OPTION__NOP__LEN continue if (value := frame[offset + 1]) < 2: diff --git a/tests/unit/protocols/icmp6/test__icmp6__nd__option__unknown.py b/tests/unit/protocols/icmp6/test__icmp6__nd__option__unknown.py index 69e46f96..cc09f111 100644 --- a/tests/unit/protocols/icmp6/test__icmp6__nd__option__unknown.py +++ b/tests/unit/protocols/icmp6/test__icmp6__nd__option__unknown.py @@ -41,7 +41,7 @@ from pytcp.lib.int_checks import UINT_8__MAX, UINT_8__MIN from pytcp.protocols.icmp6.icmp6__errors import Icmp6IntegrityError from pytcp.protocols.icmp6.message.nd.option.icmp6_nd_option import ( - ICMP6__ND_OPTION__LEN, + ICMP6__ND__OPTION__LEN, Icmp6NdOptionType, ) from pytcp.protocols.icmp6.message.nd.option.icmp6_nd_option__unknown import ( @@ -159,7 +159,7 @@ def test__icmp6__nd__option__unknown__len__mismatch(self) -> None: """ self._option_args["len"] = value = ( - ICMP6__ND_OPTION__LEN + len(self._option_args["data"]) + 8 # type: ignore + ICMP6__ND__OPTION__LEN + len(self._option_args["data"]) + 8 # type: ignore ) with self.assertRaises(AssertionError) as error: @@ -169,7 +169,7 @@ def test__icmp6__nd__option__unknown__len__mismatch(self) -> None: str(error.exception), ( "The 'len' field must reflect the length of the 'data' field. " - f"Got: {value} != {ICMP6__ND_OPTION__LEN + len(self._option_args['data'])}" # type: ignore + f"Got: {value} != {ICMP6__ND__OPTION__LEN + len(self._option_args['data'])}" # type: ignore ), ) diff --git a/tests/unit/protocols/ip4/test__ip4__option__eol.py b/tests/unit/protocols/ip4/test__ip4__option__eol.py index 9671253c..a913ab3a 100644 --- a/tests/unit/protocols/ip4/test__ip4__option__eol.py +++ b/tests/unit/protocols/ip4/test__ip4__option__eol.py @@ -40,7 +40,7 @@ from pytcp.protocols.ip4.options.ip4_option import Ip4OptionType from pytcp.protocols.ip4.options.ip4_option__eol import ( - IP4__OPTION_EOL__LEN, + IP4__OPTION__EOL__LEN, Ip4OptionEol, ) @@ -65,7 +65,7 @@ class TestIp4OptionEolAsserts(TestCase): "__repr__": "Ip4OptionEol()", "__bytes__": b"\x00", "type": Ip4OptionType.EOL, - "len": IP4__OPTION_EOL__LEN, + "len": IP4__OPTION__EOL__LEN, }, }, ] diff --git a/tests/unit/protocols/ip4/test__ip4__option__nop.py b/tests/unit/protocols/ip4/test__ip4__option__nop.py index dd5a3e0e..0b326e17 100644 --- a/tests/unit/protocols/ip4/test__ip4__option__nop.py +++ b/tests/unit/protocols/ip4/test__ip4__option__nop.py @@ -40,7 +40,7 @@ from pytcp.protocols.ip4.options.ip4_option import Ip4OptionType from pytcp.protocols.ip4.options.ip4_option__nop import ( - IP4__OPTION_NOP__LEN, + IP4__OPTION__NOP__LEN, Ip4OptionNop, ) @@ -65,7 +65,7 @@ class TestIp4OptionNopAsserts(TestCase): "__repr__": "Ip4OptionNop()", "__bytes__": b"\x01", "type": Ip4OptionType.NOP, - "len": IP4__OPTION_NOP__LEN, + "len": IP4__OPTION__NOP__LEN, }, }, ] diff --git a/tests/unit/protocols/tcp/test__tcp__option__eol.py b/tests/unit/protocols/tcp/test__tcp__option__eol.py index 39752688..eb8bf801 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__eol.py +++ b/tests/unit/protocols/tcp/test__tcp__option__eol.py @@ -40,7 +40,7 @@ from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__eol import ( - TCP__OPTION_EOL__LEN, + TCP__OPTION__EOL__LEN, TcpOptionEol, ) @@ -65,7 +65,7 @@ class TestTcpOptionEolAsserts(TestCase): "__repr__": "TcpOptionEol()", "__bytes__": b"\x00", "type": TcpOptionType.EOL, - "len": TCP__OPTION_EOL__LEN, + "len": TCP__OPTION__EOL__LEN, }, }, ] diff --git a/tests/unit/protocols/tcp/test__tcp__option__mss.py b/tests/unit/protocols/tcp/test__tcp__option__mss.py index adf11e87..4832dfa1 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__mss.py +++ b/tests/unit/protocols/tcp/test__tcp__option__mss.py @@ -41,7 +41,7 @@ from pytcp.lib.int_checks import UINT_16__MAX, UINT_16__MIN from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__mss import ( - TCP__OPTION_MSS__LEN, + TCP__OPTION__MSS__LEN, TcpOptionMss, ) from pytcp.protocols.tcp.tcp__errors import TcpIntegrityError @@ -107,7 +107,7 @@ def test__tcp__option__mss__mss__over_max(self) -> None: "__repr__": "TcpOptionMss(mss=65535)", "__bytes__": b"\x02\x04\xff\xff", "type": TcpOptionType.MSS, - "len": TCP__OPTION_MSS__LEN, + "len": TCP__OPTION__MSS__LEN, "mss": 65535, }, }, diff --git a/tests/unit/protocols/tcp/test__tcp__option__nop.py b/tests/unit/protocols/tcp/test__tcp__option__nop.py index 1a6662fb..1494b11a 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__nop.py +++ b/tests/unit/protocols/tcp/test__tcp__option__nop.py @@ -40,7 +40,7 @@ from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__nop import ( - TCP__OPTION_NOP__LEN, + TCP__OPTION__NOP__LEN, TcpOptionNop, ) @@ -65,7 +65,7 @@ class TestTcpOptionNopAsserts(TestCase): "__repr__": "TcpOptionNop()", "__bytes__": b"\x01", "type": TcpOptionType.NOP, - "len": TCP__OPTION_NOP__LEN, + "len": TCP__OPTION__NOP__LEN, }, }, ] diff --git a/tests/unit/protocols/tcp/test__tcp__option__sack.py b/tests/unit/protocols/tcp/test__tcp__option__sack.py index fd6327ce..dfcc690d 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__sack.py +++ b/tests/unit/protocols/tcp/test__tcp__option__sack.py @@ -40,8 +40,8 @@ from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__sack import ( - TCP__OPTION_SACK__LEN, - TCP__OPTION_SACK__MAX_BLOCK_NUM, + TCP__OPTION__SACK__LEN, + TCP__OPTION__SACK__MAX_BLOCK_NUM, TcpOptionSack, TcpSackBlock, ) @@ -68,7 +68,7 @@ def test__tcp__option__sack__blocks__too_many(self) -> None: provided 'blocks' argument has too many elements. """ - value = TCP__OPTION_SACK__MAX_BLOCK_NUM + 1 + value = TCP__OPTION__SACK__MAX_BLOCK_NUM + 1 self._option_args["blocks"] = [TcpSackBlock(0, 0)] * value with self.assertRaises(AssertionError) as error: @@ -76,7 +76,7 @@ def test__tcp__option__sack__blocks__too_many(self) -> None: self.assertEqual( str(error.exception), - f"The 'blocks' field must have at most {TCP__OPTION_SACK__MAX_BLOCK_NUM} " + f"The 'blocks' field must have at most {TCP__OPTION__SACK__MAX_BLOCK_NUM} " f"elements. Got: {value}", ) @@ -94,7 +94,7 @@ def test__tcp__option__sack__blocks__too_many(self) -> None: "__repr__": "TcpOptionSack(blocks=[])", "__bytes__": b"\x05\x02", "type": TcpOptionType.SACK, - "length": TCP__OPTION_SACK__LEN, + "length": TCP__OPTION__SACK__LEN, "blocks": [], }, }, @@ -114,7 +114,7 @@ def test__tcp__option__sack__blocks__too_many(self) -> None: ), "__bytes__": b"\x05\x0a\xff\xff\xff\xff\xff\xff\xff\xff", "type": TcpOptionType.SACK, - "length": TCP__OPTION_SACK__LEN + 8 * 1, + "length": TCP__OPTION__SACK__LEN + 8 * 1, "blocks": [TcpSackBlock(4294967295, 4294967295)], }, }, @@ -140,7 +140,7 @@ def test__tcp__option__sack__blocks__too_many(self) -> None: b"\x11\x5c\x00\x00\x15\xb3\x00\x00\x1a\x0a" ), "type": TcpOptionType.SACK, - "length": TCP__OPTION_SACK__LEN + 8 * 3, + "length": TCP__OPTION__SACK__LEN + 8 * 3, "blocks": [ TcpSackBlock(1111, 2222), TcpSackBlock(3333, 4444), @@ -172,7 +172,7 @@ def test__tcp__option__sack__blocks__too_many(self) -> None: b"\x03\x78" ), "type": TcpOptionType.SACK, - "length": TCP__OPTION_SACK__LEN + 8 * 4, + "length": TCP__OPTION__SACK__LEN + 8 * 4, "blocks": [ TcpSackBlock(111, 222), TcpSackBlock(333, 444), diff --git a/tests/unit/protocols/tcp/test__tcp__option__sackperm.py b/tests/unit/protocols/tcp/test__tcp__option__sackperm.py index fef0f3c3..55ce35ed 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__sackperm.py +++ b/tests/unit/protocols/tcp/test__tcp__option__sackperm.py @@ -40,7 +40,7 @@ from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__sackperm import ( - TCP__OPTION_SACKPERM__LEN, + TCP__OPTION__SACKPERM__LEN, TcpOptionSackperm, ) from pytcp.protocols.tcp.tcp__errors import TcpIntegrityError @@ -66,7 +66,7 @@ class TestTcpOptionSackpermAsserts(TestCase): "__repr__": "TcpOptionSackperm()", "__bytes__": b"\x04\x02", "type": TcpOptionType.SACKPERM, - "len": TCP__OPTION_SACKPERM__LEN, + "len": TCP__OPTION__SACKPERM__LEN, }, }, ] diff --git a/tests/unit/protocols/tcp/test__tcp__option__timestamps.py b/tests/unit/protocols/tcp/test__tcp__option__timestamps.py index 1ec87c8f..454cedc3 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__timestamps.py +++ b/tests/unit/protocols/tcp/test__tcp__option__timestamps.py @@ -41,7 +41,7 @@ from pytcp.lib.int_checks import UINT_32__MAX, UINT_32__MIN from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__timestamps import ( - TCP__OPTION_TIMESTAMPS__LEN, + TCP__OPTION__TIMESTAMPS__LEN, TcpOptionTimestamps, ) from pytcp.protocols.tcp.tcp__errors import TcpIntegrityError @@ -143,7 +143,7 @@ def test__tcp__option__timestamps__tsecr__over_max(self) -> None: ), "__bytes__": b"\x08\x0a\xff\xff\xff\xff\xff\xff\xff\xff", "type": TcpOptionType.TIMESTAMPS, - "len": TCP__OPTION_TIMESTAMPS__LEN, + "len": TCP__OPTION__TIMESTAMPS__LEN, "tsval": 4294967295, "tsecr": 4294967295, }, @@ -162,7 +162,7 @@ def test__tcp__option__timestamps__tsecr__over_max(self) -> None: ), "__bytes__": b"\x08\x0a\x42\x3a\x35\xc7\x84\x74\x6b\x8e", "type": TcpOptionType.TIMESTAMPS, - "len": TCP__OPTION_TIMESTAMPS__LEN, + "len": TCP__OPTION__TIMESTAMPS__LEN, "tsval": 1111111111, "tsecr": 2222222222, }, diff --git a/tests/unit/protocols/tcp/test__tcp__option__wscale.py b/tests/unit/protocols/tcp/test__tcp__option__wscale.py index 662a628d..30e2418a 100644 --- a/tests/unit/protocols/tcp/test__tcp__option__wscale.py +++ b/tests/unit/protocols/tcp/test__tcp__option__wscale.py @@ -41,7 +41,7 @@ from pytcp.lib.int_checks import UINT_8__MIN from pytcp.protocols.tcp.options.tcp_option import TcpOptionType from pytcp.protocols.tcp.options.tcp_option__wscale import ( - TCP__OPTION_WSCALE__MAX_VALUE, + TCP__OPTION__WSCALE__MAX_VALUE, TcpOptionWscale, ) from pytcp.protocols.tcp.tcp__errors import TcpIntegrityError @@ -75,7 +75,7 @@ def test__tcp__option__wscale__wscale__under_min(self) -> None: self.assertEqual( str(error.exception), "The 'wscale' field must be a 8-bit unsigned integer less than " - f"or equal to {TCP__OPTION_WSCALE__MAX_VALUE}. Got: {value}", + f"or equal to {TCP__OPTION__WSCALE__MAX_VALUE}. Got: {value}", ) def test__tcp__option__wscale__wscale__over_max(self) -> None: @@ -84,7 +84,7 @@ def test__tcp__option__wscale__wscale__over_max(self) -> None: provided 'wscale' argument is higher than the maximum supported value. """ - self._option_args["wscale"] = value = TCP__OPTION_WSCALE__MAX_VALUE + 1 + self._option_args["wscale"] = value = TCP__OPTION__WSCALE__MAX_VALUE + 1 with self.assertRaises(AssertionError) as error: TcpOptionWscale(**self._option_args) @@ -92,7 +92,7 @@ def test__tcp__option__wscale__wscale__over_max(self) -> None: self.assertEqual( str(error.exception), "The 'wscale' field must be a 8-bit unsigned integer less than " - f"or equal to {TCP__OPTION_WSCALE__MAX_VALUE}. Got: {value}", + f"or equal to {TCP__OPTION__WSCALE__MAX_VALUE}. Got: {value}", )