mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
filesystem: Fix TLV decode/encode
We cannot call a method of a class without instantiating it Change-Id: I6d7c1bf49a8eaf3d8e50fb12888bf3d5b46b6c55
This commit is contained in:
@@ -532,8 +532,9 @@ class TransparentEF(CardEF):
|
||||
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 @@ class TransparentEF(CardEF):
|
||||
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 @@ class TransparentEF(CardEF):
|
||||
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)
|
||||
|
||||
def encode_hex(self, abstract_data:dict) -> str:
|
||||
@@ -609,8 +612,9 @@ class TransparentEF(CardEF):
|
||||
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 @@ class LinFixedEF(CardEF):
|
||||
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 @@ class LinFixedEF(CardEF):
|
||||
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 @@ class LinFixedEF(CardEF):
|
||||
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 @@ class LinFixedEF(CardEF):
|
||||
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 @@ class TransRecEF(TransparentEF):
|
||||
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 @@ class TransRecEF(TransparentEF):
|
||||
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 @@ class TransRecEF(TransparentEF):
|
||||
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 @@ class TransRecEF(TransparentEF):
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user