commands: do not check SW manually, use send_apdu_checksw()
The transport layer provides a method send_apdu_checksw to send APDUs
and to be sure the SW is the expected one. Given that, there is no need
to verify the SW manually. The exception of send_apdu_checksw will catch
the problem and also display the SW in a human readable form.
Change-Id: I9ce556ac0b7bb21c5c5a27170c32af0152255b79
Related: OS#5275
diff --git a/pySim/utils.py b/pySim/utils.py
index 68de14a..8f2b2e9 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -5,6 +5,7 @@
import json
import abc
+import string
from io import BytesIO
from typing import Optional, List, Dict, Any, Tuple
@@ -89,6 +90,20 @@
def half_round_up(n:int) -> int:
return (n + 1)//2
+def str_sanitize(s:str) -> str:
+ """replace all non printable chars, line breaks and whitespaces, with ' ', make sure that
+ there are no whitespaces at the end and at the beginning of the string.
+
+ Args:
+ s : string to sanitize
+ Returns:
+ filtered result of string 's'
+ """
+
+ chars_to_keep = string.digits + string.ascii_letters + string.punctuation
+ res = ''.join([c if c in chars_to_keep else ' ' for c in s])
+ return res.strip()
+
#########################################################################
# poor man's COMPREHENSION-TLV decoder.
#########################################################################