laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/27100 )
Change subject: filesystem: Fix TLV decode/encode ......................................................................
filesystem: Fix TLV decode/encode
We cannot call a method of a class without instantiating it
Change-Id: I6d7c1bf49a8eaf3d8e50fb12888bf3d5b46b6c55 --- M pySim/filesystem.py 1 file changed, 36 insertions(+), 24 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/00/27100/1
diff --git a/pySim/filesystem.py b/pySim/filesystem.py index 3e9d52e..d60068d 100644 --- a/pySim/filesystem.py +++ b/pySim/filesystem.py @@ -532,8 +532,9 @@ if self._construct: return parse_construct(self._construct, raw_bin_data) elif self._tlv: - self._tlv.from_tlv(raw_bin_data) - return self._tlv.to_dict() + t = self._tlv() + t.from_tlv(raw_bin_data) + return t.to_dict() return {'raw': raw_bin_data.hex()}
def decode_hex(self, raw_hex_data:str) -> dict: @@ -558,8 +559,9 @@ if self._construct: return parse_construct(self._construct, raw_bin_data) elif self._tlv: - self._tlv.from_tlv(raw_bin_data) - return self._tlv.to_dict() + t = self._tlv() + t.from_tlv(raw_bin_data) + return t.to_dict() return {'raw': raw_bin_data.hex()}
def encode_bin(self, abstract_data:dict) -> bytearray: @@ -583,8 +585,9 @@ if self._construct: return self._construct.build(abstract_data) elif self._tlv: - self._tlv.from_dict(abstract_data) - return self._tlv.to_tlv() + t = self._tlv() + t.from_dict(raw_bin_data) + return t.to_tlv() raise NotImplementedError("%s encoder not yet implemented. Patches welcome." % self)
def encode_hex(self, abstract_data:dict) -> str: @@ -609,8 +612,9 @@ if self._construct: return b2h(self._construct.build(abstract_data)) elif self._tlv: - self._tlv.from_dict(abstract_data) - return b2h(self._tlv.to_tlv()) + t = self._tlv() + t.from_dict(abstract_data) + return b2h(t.to_tlv()) raise NotImplementedError("%s encoder not yet implemented. Patches welcome." % self)
@@ -767,8 +771,9 @@ if self._construct: return parse_construct(self._construct, raw_bin_data) elif self._tlv: - self._tlv.from_tlv(raw_bin_data) - return self._tlv.to_dict() + t = self._tlv() + t.from_tlv(raw_bin_data) + return t.to_dict() return {'raw': raw_bin_data.hex()}
def decode_record_bin(self, raw_bin_data:bytearray) -> dict: @@ -793,8 +798,9 @@ if self._construct: return parse_construct(self._construct, raw_bin_data) elif self._tlv: - self._tlv.from_tlv(raw_bin_data) - return self._tlv.to_dict() + t = self._tlv() + t.from_tlv(raw_bin_data) + return t.to_dict() return {'raw': raw_hex_data}
def encode_record_hex(self, abstract_data:dict) -> str: @@ -819,8 +825,9 @@ if self._construct: return b2h(self._construct.build(abstract_data)) elif self._tlv: - self._tlv.from_dict(abstract_data) - return b2h(self._tlv.to_tlv()) + t = self._tlv() + t.from_dict(abstract_data) + return b2h(t.to_tlv()) raise NotImplementedError("%s encoder not yet implemented. Patches welcome." % self)
def encode_record_bin(self, abstract_data:dict) -> bytearray: @@ -844,8 +851,9 @@ if self._construct: return self._construct.build(abstract_data) elif self._tlv: - self._tlv.from_dict(abstract_data) - return self._tlv.to_tlv() + t = self._tlv() + t.from_dict(abstract_data) + return t.to_tlv() raise NotImplementedError("%s encoder not yet implemented. Patches welcome." % self)
class CyclicEF(LinFixedEF): @@ -901,8 +909,9 @@ if self._construct: return parse_construct(self._construct, raw_bin_data) elif self._tlv: - self._tlv.from_tlv(raw_bin_data) - return self._tlv.to_dict() + t = self._tlv() + t.from_tlv(raw_bin_data) + return t.to_dict() return {'raw': raw_hex_data}
def decode_record_bin(self, raw_bin_data:bytearray) -> dict: @@ -927,8 +936,9 @@ if self._construct: return parse_construct(self._construct, raw_bin_data) elif self._tlv: - self._tlv.from_tlv(raw_bin_data) - return self._tlv.to_dict() + t = self._tlv() + t.from_tlv(raw_bin_data) + return t.to_dict() return {'raw': raw_hex_data}
def encode_record_hex(self, abstract_data:dict) -> str: @@ -952,8 +962,9 @@ if self._construct: return b2h(filter_dict(self._construct.build(abstract_data))) elif self._tlv: - self._tlv.from_dict(abstract_data) - return b2h(self._tlv.to_tlv()) + t = self._tlv() + t.from_dict(abstract_data) + return b2h(t.to_tlv()) raise NotImplementedError("%s encoder not yet implemented. Patches welcome." % self)
def encode_record_bin(self, abstract_data:dict) -> bytearray: @@ -977,8 +988,9 @@ if self._construct: return filter_dict(self._construct.build(abstract_data)) elif self._tlv: - self._tlv.from_dict(abstract_data) - return self._tlv.to_tlv() + t = self._tlv() + t.from_dict(abstract_data) + return t.to_tlv() raise NotImplementedError("%s encoder not yet implemented. Patches welcome." % self)
def _decode_bin(self, raw_bin_data:bytearray):