<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23170">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">introduce SwMatchError exception<br><br>This allows callers further up the stack to catch the exception and<br>interpret it in some way (like decoding the number of remaining tries<br>in case of authentication errors)<br><br>Change-Id: Ia59962978745aef7038f750fa23f8dfc820645f4<br>---<br>M pySim/exceptions.py<br>M pySim/transport/__init__.py<br>2 files changed, 13 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/70/23170/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim/exceptions.py b/pySim/exceptions.py</span><br><span>index c0cf1e7..fdf07aa 100644</span><br><span>--- a/pySim/exceptions.py</span><br><span>+++ b/pySim/exceptions.py</span><br><span>@@ -5,6 +5,7 @@</span><br><span> </span><br><span> #</span><br><span> # Copyright (C) 2009-2010  Sylvain Munaut <tnt@246tNt.com></span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright (C) 2021 Harald Welte <laforge@osmocom.org></span><br><span> #</span><br><span> # This program is free software: you can redistribute it and/or modify</span><br><span> # it under the terms of the GNU General Public License as published by</span><br><span>@@ -36,3 +37,12 @@</span><br><span> </span><br><span> class ReaderError(Exception):</span><br><span>        pass</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+class SwMatchError(Exception):</span><br><span style="color: hsl(120, 100%, 40%);">+        """Raised when an operation specifies an expected SW but the actual SW from</span><br><span style="color: hsl(120, 100%, 40%);">+       the card doesn't match."""</span><br><span style="color: hsl(120, 100%, 40%);">+      def __init__(self, sw_actual, sw_expected):</span><br><span style="color: hsl(120, 100%, 40%);">+           self.sw_actual = sw_actual</span><br><span style="color: hsl(120, 100%, 40%);">+            self.sw_expected = sw_expected</span><br><span style="color: hsl(120, 100%, 40%);">+        def __str__(self):</span><br><span style="color: hsl(120, 100%, 40%);">+            return "Received %s but expected %s from card" % (self.sw_actual, self.sw_expected)</span><br><span>diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py</span><br><span>index 8e009ee..27901d7 100644</span><br><span>--- a/pySim/transport/__init__.py</span><br><span>+++ b/pySim/transport/__init__.py</span><br><span>@@ -3,6 +3,8 @@</span><br><span> """ pySim: PCSC reader transport link base</span><br><span> """</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+from pySim.exceptions import *</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #</span><br><span> # Copyright (C) 2009-2010  Sylvain Munaut <tnt@246tNt.com></span><br><span> #</span><br><span>@@ -100,5 +102,5 @@</span><br><span>                                sw_masked = sw_masked + rv[1][i].lower()</span><br><span> </span><br><span>                 if sw.lower() != sw_masked:</span><br><span style="color: hsl(0, 100%, 40%);">-                     raise RuntimeError("SW match failed! Expected %s and got %s." % (sw.lower(), rv[1]))</span><br><span style="color: hsl(120, 100%, 40%);">+                        raise SwMatchError(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/c/pysim/+/23170">change 23170</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/c/pysim/+/23170"/><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-Change-Id: Ia59962978745aef7038f750fa23f8dfc820645f4 </div>
<div style="display:none"> Gerrit-Change-Number: 23170 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>