fix(?) extended + long-extended decoding

This commit is contained in:
Istvan Ruzman
2020-09-05 16:21:19 +02:00
parent 7c6e97a9b1
commit d51d3efe4e

View File

@@ -118,11 +118,9 @@ def pre_decode_attributes( # pylint: disable=too-many-branches
tmp_attributes = decode_vsa(rad_dict, key, value, offset)
else:
if attr_def.datatype == Datatype.extended:
key, value, modifier = decode_extended(key, value, offset)
key, value, modifier = decode_extended(key, value)
elif attr_def.datatype == Datatype.longextended:
key, value, modifier = decode_longextended(
key, value, offset
)
key, value, modifier = decode_longextended(key, value)
elif attr_def.datatype == Datatype.evs:
# Shouldn't this be part of extended/longextended?
key, value, modifier = decode_evs(key, value, offset)
@@ -130,7 +128,7 @@ def pre_decode_attributes( # pylint: disable=too-many-branches
key, value, modifier = decode_concat(key, value, offset)
else:
modifier = 2
# Redundand in the "normal" case
# Redundant in the "normal" case
tmp_attributes = [(key, value, offset + modifier)]
except (KeyError, IndexError):
# We do not know the TLV, but the packet seems to be well-formed so far
@@ -227,21 +225,17 @@ def decode_vsa(
return vendor_attributes
def decode_extended(
key: int, value: bytes, offset: int
) -> SpecialTlvDescription:
def decode_extended(key: int, value: bytes) -> SpecialTlvDescription:
"""Decode an Attribute of type extended"""
key = (key, value[0])
value = value[1 : length - 2]
value = value[1:-2]
return (key, value, 3)
def decode_longextended(
key: int, value: bytes, offset: int
) -> SpecialTlvDescription:
def decode_longextended(key: int, value: bytes) -> SpecialTlvDescription:
"""Decode an Attribute of type long-extended"""
key = (key, value[0])
value = value[2 : length - 3]
value = value[2:-3]
return (key, value, 4)