Prepare for decoding/encoding records differently based on record number
In their infinite wisdom, the authors of the EIRENE FFFIS for GSM-R SIM
cards invented yet a new way of encoding data in SIM card files: The
first record of a file may be encoded differently than further records
of files.
Let's add the required infrastructure to pySim so that the encode and
decode methods for record-oriented files get passed in the current
record number.
Change-Id: I02d6942016dd0631b21d1fd301711c13cb27962b
Related: OS#5784
diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py
index 83ddb85..e180b28 100644
--- a/pySim/ts_102_221.py
+++ b/pySim/ts_102_221.py
@@ -608,13 +608,13 @@
super().__init__(fid, sfid=sfid, name=name,
desc=desc, rec_len=2, size=(2, None))
- def _decode_record_bin(self, bin_data):
+ def _decode_record_bin(self, bin_data, **kwargs):
if bin_data == b'\xff\xff':
return None
else:
return bin_data.decode('ascii')
- def _encode_record_bin(self, in_json):
+ def _encode_record_bin(self, in_json, **kwargs):
if in_json is None:
return b'\xff\xff'
else:
@@ -665,7 +665,7 @@
raise ValueError
return by_mode
- def _decode_record_bin(self, raw_bin_data):
+ def _decode_record_bin(self, raw_bin_data, **kwargs):
# we can only guess if we should decode for EF or DF here :(
arr_seq = DataObjectSequence('arr', sequence=[AM_DO_EF, SC_DO])
dec = arr_seq.decode_multi(raw_bin_data)
@@ -673,7 +673,7 @@
# 'un-flattening' decoder, and hence would be unable to encode :(
return dec[0]
- def _encode_record_bin(self, in_json):
+ def _encode_record_bin(self, in_json, **kwargs):
# we can only guess if we should decode for EF or DF here :(
arr_seq = DataObjectSequence('arr', sequence=[AM_DO_EF, SC_DO])
return arr_seq.encode_multi(in_json)