From edf266726d256ff472fbef2dfbfecbd505e586ba Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 23 Aug 2024 12:25:54 +0200 Subject: [PATCH] filesystem: add command to delete all contents from a BER-TLV EF When working with BER-TLF files, we can only delete one tag at a time. There is no way to delete all tags at once. This may make working with BER-TLV files difficult, in particular when scripting is used and the script needs to start with an empty file. Also export has problems, since it does not reset the file before setting the new values there may be unexpected results in case there still tags in the file that are not set during import. To fill the gap, let's add a commandd that deletes all tags in a BER-TLV EF at once. Related: OS#6531 Change-Id: I5d6bcfe865df7cb8fa6dd0052cab3b364d929f94 --- pySim/filesystem.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pySim/filesystem.py b/pySim/filesystem.py index 35af140c..d5e99a49 100644 --- a/pySim/filesystem.py +++ b/pySim/filesystem.py @@ -1338,6 +1338,12 @@ class BerTlvEF(CardEF): if data: self._cmd.poutput(data) + def do_delete_all(self, opts): + """Delete all data from a BER-TLV EF""" + tags = self._cmd.lchan.retrieve_tags() + for tag in tags: + self._cmd.lchan.set_data(tag, None) + def __init__(self, fid: str, sfid: str = None, name: str = None, desc: str = None, parent: CardDF = None, size: Size = (1, None), **kwargs): """ @@ -1374,6 +1380,7 @@ class BerTlvEF(CardEF): if tags == []: export_str += "# empty file, no tags" else: + export_str += "delete_all\n" for t in tags: result = lchan.retrieve_data(t) (tag, l, val, remainer) = bertlv_parse_one(h2b(result[0]))