<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/9571">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Harald Welte: Looks good to me, approved; Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">__init__: allow wildcards in expected SW for send_apdu_checksw()<br><br>The method send_apdu_checksw() is used to check the SW of the final<br>response against some pre defined value. However, in many cases the<br>last two digits of the SW are used to return varying information<br>(e.g. length information or a more specific status info). To cover<br>those cases it would be helfpul to define status words that contain<br>wildcards (e.g. 61**) in order to be able to accept all SWs from<br>6100 to 61ff.<br><br>- When the user supplies an expected SW with wildcards, mask out<br>  those digits in the response before comparing<br><br>Change-Id: I5bfc0522b4228b5d9b3415f6e708abcf0da0a7b7<br>---<br>M pySim/transport/__init__.py<br>1 file changed, 13 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py</span><br><span>index dd04bba..0a71117 100644</span><br><span>--- a/pySim/transport/__init__.py</span><br><span>+++ b/pySim/transport/__init__.py</span><br><span>@@ -77,12 +77,23 @@</span><br><span>          """send_apdu_checksw(pdu,sw): Sends an APDU and check returned SW</span><br><span> </span><br><span>                    pdu    : string of hexadecimal characters (ex. "A0A40000023F00")</span><br><span style="color: hsl(0, 100%, 40%);">-              sw     : string of 4 hexadecimal characters (ex. "9000")</span><br><span style="color: hsl(120, 100%, 40%);">+            sw     : string of 4 hexadecimal characters (ex. "9000"). The</span><br><span style="color: hsl(120, 100%, 40%);">+                        user may mask out certain digits using a '?' to add some</span><br><span style="color: hsl(120, 100%, 40%);">+                      ambiguity if needed.</span><br><span>                return : tuple(data, sw), where</span><br><span>                       data : string (in hex) of returned data (ex. "074F4EFFFF")</span><br><span>                         sw   : string (in hex) of status word (ex. "9000")</span><br><span>             """</span><br><span>           rv = self.send_apdu(pdu)</span><br><span style="color: hsl(0, 100%, 40%);">-                if sw.lower() != rv[1]:</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                # Create a masked version of the returned status word</span><br><span style="color: hsl(120, 100%, 40%);">+              sw_masked = ""</span><br><span style="color: hsl(120, 100%, 40%);">+              for i in range(0, 4):</span><br><span style="color: hsl(120, 100%, 40%);">+                 if sw.lower()[i] == '?':</span><br><span style="color: hsl(120, 100%, 40%);">+                              sw_masked = sw_masked + '?'</span><br><span style="color: hsl(120, 100%, 40%);">+                   else:</span><br><span style="color: hsl(120, 100%, 40%);">+                         sw_masked = sw_masked + rv[1][i].lower()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+            if sw.lower() != sw_masked:</span><br><span>                  raise RuntimeError("SW match failed ! Expected %s and got %s." % (sw.lower(), rv[1]))</span><br><span>              return rv</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/9571">change 9571</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/9571"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I5bfc0522b4228b5d9b3415f6e708abcf0da0a7b7 </div>
<div style="display:none"> Gerrit-Change-Number: 9571 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>