laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/39293?usp=email )


Change subject: align get_atr() return value type
......................................................................

align get_atr() return value type

type annotations claimed the return type was Hexstr, but in reality
it was a list of integers.  Let's fix that.

Change-Id: I01b247dad40ec986cf199302f8e92d16848bd499
Closes: OS#6322
---
M pySim/filesystem.py
M pySim/legacy/cards.py
M pySim/runtime.py
M pySim/transport/pcsc.py
M pySim/transport/serial.py
5 files changed, 21 insertions(+), 21 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/93/39293/1

diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 6e8852a..5c60968 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -35,7 +35,7 @@
 from cmd2 import CommandSet, with_default_category
 from smartcard.util import toBytes

-from osmocom.utils import h2b, b2h, is_hex, auto_int, auto_uint8, auto_uint16, 
is_hexstr, JsonEncoder
+from osmocom.utils import h2b, b2h, is_hex, auto_int, auto_uint8, auto_uint16, 
is_hexstr, JsonEncoder, hexstr
 from osmocom.tlv import bertlv_parse_one
 from osmocom.construct import filter_dict, parse_construct, build_construct

@@ -1528,10 +1528,9 @@
     @classmethod
     def match(cls, scc: SimCardCommands) -> bool:
         """Test if given card matches this model."""
-        card_atr = scc.get_atr()
+        card_atr = hexstr(scc.get_atr())
         for atr in cls._atrs:
-            atr_bin = toBytes(atr)
-            if atr_bin == card_atr:
+            if hexstr(atr) == card_atr:
                 print("Detected CardModel:", cls.__name__)
                 return True
         return False
diff --git a/pySim/legacy/cards.py b/pySim/legacy/cards.py
index 1f5db8a..414bcdc 100644
--- a/pySim/legacy/cards.py
+++ b/pySim/legacy/cards.py
@@ -5,6 +5,7 @@
 import abc
 from smartcard.util import toBytes
 from pytlv.TLV import *
+from osmocom.utils import hexstr

 from pySim.cards import SimCardBase, UiccCardBase
 from pySim.utils import dec_iccid, enc_iccid, dec_imsi, enc_imsi
@@ -781,7 +782,7 @@
     def autodetect(kls, scc):
         try:
             # Look for ATR
-            if scc.get_atr() == toBytes("3B 99 18 00 11 88 22 33 44 55 66 77 
60"):
+            if scc.get_atr() == hexstr("3B 99 18 00 11 88 22 33 44 55 66 77 
60"):
                 return kls(scc)
         except:
             return None
@@ -826,7 +827,7 @@
     def autodetect(kls, scc):
         try:
             # Look for ATR
-            if scc.get_atr() == toBytes("3B 7D 94 00 00 55 55 53 0A 74 86 93 
0B 24 7C 4D 54 68"):
+            if scc.get_atr() == hexstr("3B 7D 94 00 00 55 55 53 0A 74 86 93 0B 
24 7C 4D 54 68"):
                 return kls(scc)
         except:
             return None
@@ -904,7 +905,7 @@
     def autodetect(kls, scc):
         try:
             # Look for ATR
-            if scc.get_atr() == toBytes("3B 9F 96 80 1F C7 80 31 A0 73 BE 21 
13 67 43 20 07 18 00 00 01 A5"):
+            if scc.get_atr() == hexstr("3B 9F 96 80 1F C7 80 31 A0 73 BE 21 13 
67 43 20 07 18 00 00 01 A5"):
                 return kls(scc)
         except:
             return None
@@ -1032,7 +1033,7 @@
     def autodetect(kls, scc):
         try:
             # Look for ATR
-            if scc.get_atr() == toBytes("3B 9F 96 80 1F C7 80 31 A0 73 BE 21 
13 67 44 22 06 10 00 00 01 A9"):
+            if scc.get_atr() == hexstr("3B 9F 96 80 1F C7 80 31 A0 73 BE 21 13 
67 44 22 06 10 00 00 01 A9"):
                 return kls(scc)
         except:
             return None
@@ -1166,7 +1167,7 @@
     def autodetect(kls, scc):
         try:
             # Look for ATR
-            if scc.get_atr() == toBytes("3B 9F 95 80 1F C3 80 31 E0 73 FE 21 
13 57 86 81 02 86 98 44 18 A8"):
+            if scc.get_atr() == hexstr("3B 9F 95 80 1F C3 80 31 E0 73 FE 21 13 
57 86 81 02 86 98 44 18 A8"):
                 return kls(scc)
         except:
             return None
@@ -1215,7 +1216,7 @@
     def autodetect(kls, scc):
         try:
             # Look for ATR
-            if scc.get_atr() == toBytes("3B 9F 95 80 1F C7 80 31 E0 73 F6 21 
13 67 4D 45 16 00 43 01 00 8F"):
+            if scc.get_atr() == hexstr("3B 9F 95 80 1F C7 80 31 E0 73 F6 21 13 
67 4D 45 16 00 43 01 00 8F"):
                 return kls(scc)
         except:
             return None
@@ -1305,18 +1306,18 @@
     def autodetect(kls, scc):
         try:
             # Try card model #1
-            atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 30 34 05 
4B A9"
-            if scc.get_atr() == toBytes(atr):
+            atr = hexstr("3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 
30 34 05 4B A9")
+            if scc.get_atr() == atr:
                 return kls(scc)

             # Try card model #2
-            atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 31 33 02 
51 B2"
-            if scc.get_atr() == toBytes(atr):
+            atr = hexstr("3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 75 
31 33 02 51 B2")
+            if scc.get_atr() == atr:
                 return kls(scc)

             # Try card model #3
-            atr = "3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 52 75 31 04 
51 D5"
-            if scc.get_atr() == toBytes(atr):
+            atr = hexstr("3B 9F 96 80 1F 87 80 31 E0 73 FE 21 1B 67 4A 4C 52 
75 31 04 51 D5")
+            if scc.get_atr() == atr:
                 return kls(scc)
         except:
             return None
diff --git a/pySim/runtime.py b/pySim/runtime.py
index 3e48f75..0eaa98a 100644
--- a/pySim/runtime.py
+++ b/pySim/runtime.py
@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

 from typing import Optional, Tuple
-from osmocom.utils import h2b, i2h, is_hex, Hexstr
+from osmocom.utils import h2b, i2h, is_hex, Hexstr, hexstr
 from osmocom.tlv import bertlv_parse_one

 from pySim.exceptions import *
@@ -141,7 +141,7 @@
                 continue
             del self.lchan[lchan_nr]
         self.adm_verified = False
-        atr = i2h(self.card.reset())
+        atr = hexstr(self.card.reset())
         if cmd_app:
             cmd_app.lchan = self.lchan[0]
         # select MF to reset internal state and to verify card really works
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index bb820ed..adac6ee 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -103,7 +103,7 @@
             raise NoCardError() from exc

     def get_atr(self) -> Hexstr:
-        return self._con.getATR()
+        return i2h(self._con.getATR())

     def disconnect(self):
         self._con.disconnect()
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index 938c319..658943b 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -21,7 +21,7 @@
 import argparse
 from typing import Optional
 import serial
-from osmocom.utils import h2b, b2h, Hexstr
+from osmocom.utils import h2b, b2h, i2h, Hexstr

 from pySim.exceptions import NoCardError, ProtocolError
 from pySim.transport import LinkBaseTpdu
@@ -96,7 +96,7 @@
         self.reset_card()

     def get_atr(self) -> Hexstr:
-        return self._atr
+        return i2h(self._atr)

     def disconnect(self):
         pass  # Nothing to do really ...

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/39293?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I01b247dad40ec986cf199302f8e92d16848bd499
Gerrit-Change-Number: 39293
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <[email protected]>

Reply via email to