Change in pysim[master]: move SW matching to a generic utility function

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Wed Mar 3 07:38:45 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/23171 )

Change subject: move SW matching to a generic utility function
......................................................................

move SW matching to a generic utility function

This will allow using it outside the transport/__init__.py

Change-Id: Id26dfefa85d91e3b3a23e0049f3b833e29cb1cef
---
M pySim/transport/__init__.py
M pySim/utils.py
2 files changed, 16 insertions(+), 9 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 00c7bd9..d720259 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -4,6 +4,7 @@
 """
 
 from pySim.exceptions import *
+from pySim.utils import sw_match
 
 #
 # Copyright (C) 2009-2010  Sylvain Munaut <tnt at 246tNt.com>
@@ -93,14 +94,6 @@
 		"""
 		rv = self.send_apdu(pdu)
 
-		# Create a masked version of the returned status word
-		sw_masked = ""
-		for i in range(0, 4):
-			if sw.lower()[i] == '?':
-				sw_masked = sw_masked + '?'
-			else:
-				sw_masked = sw_masked + rv[1][i].lower()
-
-		if sw.lower() != sw_masked:
+		if not sw_match(rv[1], sw):
 			raise SwMatchError(rv[1], sw.lower())
 		return rv
diff --git a/pySim/utils.py b/pySim/utils.py
index a733d87..bfa147b 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -759,3 +759,17 @@
 		return 0x00
 
 	return None
+
+def sw_match(sw, pattern):
+	"""Match given SW against given pattern."""
+	# Create a masked version of the returned status word
+	sw_lower = sw.lower()
+	sw_masked = ""
+	for i in range(0, 4):
+		if sw_lower[i] == '?':
+			sw_masked = sw_masked + '?'
+		elif sw_lower[i] == 'x':
+			sw_masked = sw_masked + 'x'
+		else:
+			sw_masked = sw_masked + sw_lower[i]
+	return sw_masked == pattern

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23171
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Id26dfefa85d91e3b3a23e0049f3b833e29cb1cef
Gerrit-Change-Number: 23171
Gerrit-PatchSet: 8
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210303/1c1877fd/attachment.htm>


More information about the gerrit-log mailing list