laforge has uploaded this change for review.

View Change

pySim/cards: Add type annotations

Change-Id: Id5752a64b59097584301c860ebf74d858ed3d240
---
M pySim/cards.py
1 file changed, 22 insertions(+), 11 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/92/33692/1
diff --git a/pySim/cards.py b/pySim/cards.py
index 07966d0..a9f2e59 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -24,13 +24,15 @@

from typing import Optional, Dict, Tuple
from pySim.ts_102_221 import EF_DIR, EF_ICCID
+from pySim.transport import LinkBase
import abc

from pySim.utils import *
+from pySim.commands import Path

class CardBase:
"""General base class for some kind of telecommunications card."""
- def __init__(self, scc):
+ def __init__(self, scc: LinkBase):
self._scc = scc

def reset(self):
@@ -41,12 +43,12 @@
return None
self._aids = []

- def set_apdu_parameter(self, cla, sel_ctrl):
+ def set_apdu_parameter(self, cla: Hexstr, sel_ctrl: Hexstr):
"""Set apdu parameters (class byte and selection control bytes)"""
self._scc.cla_byte = cla
self._scc.sel_ctrl = sel_ctrl

- def get_apdu_parameter(self):
+ def get_apdu_parameter(self) -> Tuple[Hexstr, Hexstr]:
"""Get apdu parameters (class byte and selection control bytes)"""
return (self._scc.cla_byte, self._scc.sel_ctrl)

@@ -54,14 +56,14 @@
print("warning: erasing is not supported for specified card type!")
return

- def file_exists(self, fid):
+ def file_exists(self, fid: Path) -> bool:
res_arr = self._scc.try_select_path(fid)
for res in res_arr:
if res[1] != '9000':
return False
return True

- def read_iccid(self):
+ def read_iccid(self) -> Tuple[Optional[Hexstr], SwHexstr]:
ef_iccid = EF_ICCID()
(res, sw) = self._scc.read_binary(ef_iccid.fid)
if sw == '9000':
@@ -80,12 +82,12 @@
class UiccCardBase(SimCardBase):
name = 'UICC'

- def __init__(self, ssc):
+ def __init__(self, ssc: LinkBase):
super(UiccCardBase, self).__init__(ssc)
# See also: ETSI TS 102 221, Table 9.3
self._adm_chv_num = 0xA0

- def read_aids(self):
+ def read_aids(self) -> List[Hexstr]:
"""Fetch all the AIDs present on UICC"""
self._aids = []
try:
@@ -104,7 +106,7 @@
return self._aids

@staticmethod
- def _get_aid(adf="usim") -> str:
+ def _get_aid(adf="usim") -> Hexstr:
aid_map = {}
# First (known) halves of the U/ISIM AID
aid_map["usim"] = "a0000000871002"
@@ -114,7 +116,7 @@
return aid_map[adf]
return None

- def _complete_aid(self, aid) -> str:
+ def _complete_aid(self, aid) -> Hexstr:
"""find the complete version of an ADF.U/ISIM AID"""
# Find full AID by partial AID:
if is_hex(aid):
@@ -123,7 +125,7 @@
return aid_known
return None

- def adf_present(self, adf="usim") -> bool:
+ def adf_present(self, adf: str = "usim") -> bool:
"""Check if the AID of the specified ADF is present in EF.DIR (call read_aids before use)"""
aid = self._get_aid(adf)
if aid:
@@ -132,7 +134,7 @@
return True
return False

- def select_adf_by_aid(self, adf="usim"):
+ def select_adf_by_aid(self, adf: str = "usim") -> Tuple[Optional[Hexstr], Optional[SwHexstr]]:
"""Select ADF.U/ISIM in the Card using its full AID"""
if is_hex(adf):
aid = adf

To view, visit change 33692. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Id5752a64b59097584301c860ebf74d858ed3d240
Gerrit-Change-Number: 33692
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange