mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-26 07:18:33 +03:00
bertlv_parse_one: Also return remainder after end of TLV
Change-Id: I10ebd87f72ee934561118b768108e5dc76277660
This commit is contained in:
@@ -265,7 +265,7 @@ class PySimCommands(CommandSet):
|
|||||||
tags = self._cmd.rs.retrieve_tags()
|
tags = self._cmd.rs.retrieve_tags()
|
||||||
for t in tags:
|
for t in tags:
|
||||||
result = self._cmd.rs.retrieve_data(t)
|
result = self._cmd.rs.retrieve_data(t)
|
||||||
(tag, l, val) = bertlv_parse_one(h2b(result[0]))
|
(tag, l, val, remainer) = bertlv_parse_one(h2b(result[0]))
|
||||||
self._cmd.poutput("set_data 0x%02x %s" % (t, b2h(val)))
|
self._cmd.poutput("set_data 0x%02x %s" % (t, b2h(val)))
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Unsupported structure "%s" of file "%s"' % (structure, filename))
|
raise RuntimeError('Unsupported structure "%s" of file "%s"' % (structure, filename))
|
||||||
|
|||||||
@@ -1260,7 +1260,7 @@ class RuntimeState(object):
|
|||||||
if not isinstance(self.selected_file, BerTlvEF):
|
if not isinstance(self.selected_file, BerTlvEF):
|
||||||
raise TypeError("Only works with BER-TLV EF")
|
raise TypeError("Only works with BER-TLV EF")
|
||||||
data, sw = self.card._scc.retrieve_data(self.selected_file.fid, 0x5c)
|
data, sw = self.card._scc.retrieve_data(self.selected_file.fid, 0x5c)
|
||||||
tag, length, value = bertlv_parse_one(h2b(data))
|
tag, length, value, remainder = bertlv_parse_one(h2b(data))
|
||||||
return list(value)
|
return list(value)
|
||||||
|
|
||||||
def set_data(self, tag:int, data_hex:str):
|
def set_data(self, tag:int, data_hex:str):
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ def bertlv_encode_len(length:int) -> bytes:
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Length > 32bits not supported")
|
raise ValueError("Length > 32bits not supported")
|
||||||
|
|
||||||
def bertlv_parse_one(binary:bytes) -> (dict, int, bytes):
|
def bertlv_parse_one(binary:bytes) -> (dict, int, bytes, bytes):
|
||||||
"""Parse a single TLV IE at the start of the given binary data.
|
"""Parse a single TLV IE at the start of the given binary data.
|
||||||
Args:
|
Args:
|
||||||
binary : binary input data of BER-TLV length field
|
binary : binary input data of BER-TLV length field
|
||||||
@@ -164,7 +164,9 @@ def bertlv_parse_one(binary:bytes) -> (dict, int, bytes):
|
|||||||
"""
|
"""
|
||||||
(tagdict, remainder) = bertlv_parse_tag(binary)
|
(tagdict, remainder) = bertlv_parse_tag(binary)
|
||||||
(length, remainder) = bertlv_parse_len(remainder)
|
(length, remainder) = bertlv_parse_len(remainder)
|
||||||
return (tagdict, length, remainder)
|
value = remainder[:length]
|
||||||
|
remainder = remainder[length:]
|
||||||
|
return (tagdict, length, value, remainder)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user