Add: evs decoding - no working tests yet
EVS decoding should be mostly working now. We do not have any tests yet, because it is unclear to me how EVS is defined in dictionaries.
This commit is contained in:
@@ -148,10 +148,34 @@ def flattened_product(l1, l2):
|
||||
return result
|
||||
|
||||
|
||||
def transform_attr_to_extended_evs(attributes):
|
||||
vendor_id = (1234).to_bytes(4, "big")
|
||||
new_attrs = []
|
||||
for attr, result in attributes:
|
||||
length = (attr[1] + 6).to_bytes(1, "big")
|
||||
orig_type = attr[0].to_bytes(1, "big")
|
||||
attr = b"\x13" + length + b"\x15" + vendor_id + orig_type + attr[2:]
|
||||
new_attrs.append((attr, result))
|
||||
return new_attrs
|
||||
|
||||
|
||||
def transform_attr_to_longextended_evs(attributes):
|
||||
vendor_id = (1234).to_bytes(4, "big")
|
||||
new_attrs = []
|
||||
for attr, result in attributes:
|
||||
length = (attr[1] + 7).to_bytes(1, "big")
|
||||
orig_type = attr[0].to_bytes(1, "big")
|
||||
attr = b"\x14" + length + b"\x15" + b"\x00" + vendor_id + orig_type + attr[2:]
|
||||
new_attrs.append((attr, result))
|
||||
return new_attrs
|
||||
|
||||
|
||||
VENDOR_TEST_ATTRIBUTES = flattened_product(VENDOR_FORMAT_COMBINATIONS, TEST_ATTRIBUTES)
|
||||
VENDOR_TAGGED_ATTRIBUTES = flattened_product(
|
||||
VENDOR_FORMAT_COMBINATIONS, TAGGED_ATTRIBUTES
|
||||
)
|
||||
VENDOR_EXTENDED_EVS_ATTRIBUTES = transform_attr_to_extended_evs(TEST_ATTRIBUTES)
|
||||
VENDOR_LONGEXTENDED_EVS_ATTRIBUTES = transform_attr_to_longextended_evs(TEST_ATTRIBUTES)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -191,6 +215,24 @@ def test_decode_attribute_rfc_tagged(radius_dictionary, attr_bytes, expected):
|
||||
assert attrs[0].tag == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("attr_bytes, expected", VENDOR_EXTENDED_EVS_ATTRIBUTES)
|
||||
def test_decode_extended_evs(radius_dictionary, attr_bytes, expected):
|
||||
raw_packet = bytes(20) + attr_bytes
|
||||
attrs = utils.decode_attributes(radius_dictionary, raw_packet)
|
||||
assert len(attrs) == 1
|
||||
assert attrs[0].value == expected
|
||||
assert attrs[0].tag == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("attr_bytes, expected", VENDOR_LONGEXTENDED_EVS_ATTRIBUTES)
|
||||
def test_decode_longextended_evs(radius_dictionary, attr_bytes, expected):
|
||||
raw_packet = bytes(20) + attr_bytes
|
||||
attrs = utils.decode_attributes(radius_dictionary, raw_packet)
|
||||
assert len(attrs) == 1
|
||||
assert attrs[0].value == expected
|
||||
assert attrs[0].tag == 0
|
||||
|
||||
|
||||
def generate_vendor_attribute(vendor_id, tlen, llen, attr_bytes):
|
||||
vendor_id = vendor_id.to_bytes(4, "big")
|
||||
vsa_length = (4 + tlen + llen + len(attr_bytes)).to_bytes(1, "big")
|
||||
|
||||
Reference in New Issue
Block a user