Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pcapkit/protocols/internet/hip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,8 @@ def _make_locator(locator: 'Optional[Data_Locator]' = None, *,
ip=value.ip.packed,
)
else:
raise ProtocolError(f'HIPv{version}: [ParamNo {code}] invalid format')
raise ProtocolError(f'HIPv{version}: [ParamNo {code}] invalid locator: '
f'must be an IPv6Address or LocatorData, not {value!r}')

traffic = locator.traffic
type = locator.type
Expand Down
10 changes: 5 additions & 5 deletions pcapkit/protocols/internet/mh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ def make(self,
elif isinstance(data, Schema_Packet):
data_val = data
else:
raise ProtocolError(f'MH: [Type {type_val}] invalid format')
raise ProtocolError(f'MH: [Type {type_val}] invalid data: unsupported type {data.__class__.__name__}')

# NOTE: The header has to be a multiple of 8 octets, so the message data
# needs padding until ``len(data) + 6`` is aligned. Rounding ``length`` up
Expand Down Expand Up @@ -7921,7 +7921,7 @@ def _make_opt_pad(self, type: 'Enum_Option', option: 'Optional[Data_PadOption]'
data = getattr(option, 'data', b'')

if type == Enum_Option.Pad1 and length != 0:
warn(f'{self.alias}: [OptNo {type}] invalid format', ProtocolWarning)
warn(f'{self.alias}: [OptNo {type}] invalid length for Pad1: {length}; falling back to PadN', ProtocolWarning)
type = Enum_Option.PadN # type: ignore[assignment]

return Schema_PadOption(
Expand Down Expand Up @@ -8029,7 +8029,7 @@ def _make_opt_bad(self, type: 'Enum_Option', option: 'Optional[Data_Authorizatio
data = option.data

if len(data) % 8 != 0:
raise ProtocolError(f'{self.alias}: [OptNo {type}] invalid format')
raise ProtocolError(f'{self.alias}: [OptNo {type}] invalid data: length must be a multiple of 8, not {len(data)}')

return Schema_AuthorizationDataOption(
type=type,
Expand Down Expand Up @@ -8359,7 +8359,7 @@ def _make_opt_auth(self, type: 'Enum_Option', option: 'Optional[Data_AuthOption]
reversed=subtype_reversed, pack=False)

if (len(data) + 6) % 4 != 0:
raise ProtocolError(f'{self.alias}: [OptNo {type}] invalid format')
raise ProtocolError(f'{self.alias}: [OptNo {type}] invalid data: length must make the option a multiple of 4, not {len(data)}')

return Schema_AuthOption(
type=type,
Expand Down Expand Up @@ -8621,7 +8621,7 @@ def _make_opt_badf(self, type: 'Enum_Option', option: 'Optional[Data_BADFOption]
data = option.data

if not data:
raise ProtocolError(f'{self.alias}: [OptNo {type}] invalid format')
raise ProtocolError(f'{self.alias}: [OptNo {type}] invalid data: must not be empty, not {data!r}')

return Schema_BADFOption(
type=type,
Expand Down
3 changes: 2 additions & 1 deletion pcapkit/protocols/misc/pcapng.py
Original file line number Diff line number Diff line change
Expand Up @@ -4921,7 +4921,8 @@ def _make_block_dsb(self, block: 'Optional[Data_DecryptionSecretsBlock]' = None,
elif isinstance(secrets_data, Schema):
secrets_data_val = secrets_data
else:
raise ProtocolError(f'PCAP-NG: [DSB] secrets {secrets_type_val} invalid format')
raise ProtocolError(f'PCAP-NG: [DSB] invalid secrets_data: '
f'unsupported type {type(secrets_data).__name__}')
# NOTE: Secrets Length excludes the padding to the next 32-bit boundary,
# which ``padding_data`` writes and the block length has to include.
if block is not None and isinstance(secrets_data_val, Schema):
Expand Down
28 changes: 14 additions & 14 deletions pcapkit/protocols/transport/sctp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ def _make_chunk_donone(self, code: 'Enum_Chunk', chunk: 'Optional[Data_UnknownCh
value = chunk.value

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

return Schema_UnknownChunk(
type=code,
Expand Down Expand Up @@ -1965,7 +1965,7 @@ def _make_chunk_data(self, code: 'Enum_Chunk', chunk: 'Optional[Data_DATAChunk]'
data = chunk.data

if not data:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid data: must not be empty')

return Schema_DATAChunk(
type=code,
Expand Down Expand Up @@ -2028,7 +2028,7 @@ def _make_chunk_init(self, code: 'Enum_Chunk', chunk: 'Optional[Data_INITChunk]'
parameters = chunk.parameters

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

if parameters is not None:
parameters_value = self._make_sctp_parameters(parameters)
Expand Down Expand Up @@ -2089,7 +2089,7 @@ def _make_chunk_init_ack(self, code: 'Enum_Chunk', chunk: 'Optional[Data_INITACK
parameters = chunk.parameters

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

if parameters is not None:
parameters_value = self._make_sctp_parameters(parameters)
Expand Down Expand Up @@ -2150,7 +2150,7 @@ def _make_chunk_sack(self, code: 'Enum_Chunk', chunk: 'Optional[Data_SACKChunk]'
dup_tsn = list(chunk.dup_tsn)

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

blocks = [] # type: list[Schema_GapAckBlock]
for block in gap_blocks or []:
Expand Down Expand Up @@ -2200,7 +2200,7 @@ def _make_chunk_heartbeat(self, code: 'Enum_Chunk', chunk: 'Optional[Data_Heartb
parameters = chunk.parameters

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

if parameters is not None:
parameters_value = self._make_sctp_parameters(parameters)
Expand Down Expand Up @@ -2241,7 +2241,7 @@ def _make_chunk_heartbeat_ack(self, code: 'Enum_Chunk', chunk: 'Optional[Data_He
parameters = chunk.parameters

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

if parameters is not None:
parameters_value = self._make_sctp_parameters(parameters)
Expand Down Expand Up @@ -2323,7 +2323,7 @@ def _make_chunk_shutdown(self, code: 'Enum_Chunk', chunk: 'Optional[Data_Shutdow
cum_tsn_ack = chunk.cum_tsn_ack

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

return Schema_ShutdownChunk(
type=code,
Expand Down Expand Up @@ -2354,7 +2354,7 @@ def _make_chunk_shutdown_ack(self, code: 'Enum_Chunk', chunk: 'Optional[Data_Shu
flags = chunk.flags

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

return Schema_ShutdownACKChunk(
type=code,
Expand Down Expand Up @@ -2387,7 +2387,7 @@ def _make_chunk_error(self, code: 'Enum_Chunk', chunk: 'Optional[Data_ErrorChunk
error = chunk.error

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

if error is not None:
error_value = self._make_sctp_causes(error)
Expand Down Expand Up @@ -2429,7 +2429,7 @@ def _make_chunk_cookie_echo(self, code: 'Enum_Chunk', chunk: 'Optional[Data_Cook
cookie = chunk.cookie

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

return Schema_CookieEchoChunk(
type=code,
Expand Down Expand Up @@ -2460,7 +2460,7 @@ def _make_chunk_cookie_ack(self, code: 'Enum_Chunk', chunk: 'Optional[Data_Cooki
flags = chunk.flags

if len(flags) != 1:
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Chunk {code}] invalid flags: must be one octet, not {flags!r}')

return Schema_CookieACKChunk(
type=code,
Expand Down Expand Up @@ -3018,7 +3018,7 @@ def _make_param_hostname(self, code: 'Enum_Parameter', param: 'Optional[Data_Hos
if param is not None:
name = param.name
elif not name.endswith(b'\x00'):
raise ProtocolError(f'{self.alias}: [Param {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Param {code}] invalid name: must be NUL-terminated, not {name!r}')

return Schema_HostNameAddressParameter(
type=code,
Expand Down Expand Up @@ -3583,7 +3583,7 @@ def _make_cause_invalid_stream(self, code: 'Enum_CauseCode', cause: 'Optional[Da
reserved = cause.reserved

if len(reserved) != 2:
raise ProtocolError(f'{self.alias}: [Cause {code}] invalid format')
raise ProtocolError(f'{self.alias}: [Cause {code}] invalid reserved: must be two octets, not {reserved!r}')

return Schema_InvalidStreamIdentifierCause(
code=code,
Expand Down
5 changes: 4 additions & 1 deletion pcapkit/protocols/transport/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2974,7 +2974,10 @@ def _make_mptcp_capable(self, subtype: 'Enum_MPTCPOption', opt: 'Optional[Data_M
fields = (skey, rkey, dl_len, checksum)
present = fields.index(None) if None in fields else len(fields)
if any(field is not None for field in fields[present:]):
raise ProtocolError(f'{self.alias}: [OptNo {Enum_Option.Multipath_TCP}] invalid format')
field_names = ('skey', 'rkey', 'dl_len', 'checksum')
index = next(i for i, field in enumerate(fields) if i >= present and field is not None)
raise ProtocolError(f'{self.alias}: [OptNo {Enum_Option.Multipath_TCP}] '
f'invalid fields: {field_names[index]!r} given without {field_names[index - 1]!r}')

return Schema_MPTCPCapable(
kind=cast('Enum_Option', Enum_Option.Multipath_TCP),
Expand Down
Loading
Loading