pySim.cards: Make file_exists() check for activated/deactivated

The Card.file_exists() method is only called by legacy pySim-{read,prog}
when it wants to determine if it can read/write a file.  Therefore
it actually doesn't only want to know if the file exists, but also
if it's not deactivated.

Change-Id: I73bd1ab3780e475c96a10cd5dbdd45b829c67335
Closes: OS#6530
This commit is contained in:
Harald Welte
2024-08-06 20:01:24 +02:00
committed by laforge
parent 4515f1cf87
commit 7d9c6583ef

View File

@@ -23,7 +23,7 @@
#
from typing import Optional, Tuple
from pySim.ts_102_221 import EF_DIR
from pySim.ts_102_221 import EF_DIR, CardProfileUICC
from pySim.ts_51_011 import DF_GSM
from pySim.utils import *
@@ -54,10 +54,17 @@ class CardBase:
print("warning: erasing is not supported for specified card type!")
def file_exists(self, fid: Path) -> bool:
"""Determine if the file exists (and is not deactivated)."""
res_arr = self._scc.try_select_path(fid)
for res in res_arr:
if res[1] != '9000':
return False
try:
d = CardProfileUICC.decode_select_response(res_arr[-1][0])
if d.get('life_cycle_status_integer', 'operational_activated') != 'operational_activated':
return False
except:
pass
return True
def read_aids(self) -> List[Hexstr]: