aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-01-21 14:10:43 +0100
committerHarald Welte <laforge@osmocom.org>2021-01-21 16:11:39 +0100
commitfd72b95dd6d4c5572b7826ce5889aac863a8a543 (patch)
tree2c3fc6a70631e55437e204f0f2902991c206b67a
parent19b286d46088b88d95b1007571fbdaa387a9d06c (diff)
introduce SwMatchError exception
This allows callers further up the stack to catch the exception and interpret it in some way (like decoding the number of remaining tries in case of authentication errors) Change-Id: Ia59962978745aef7038f750fa23f8dfc820645f4
-rw-r--r--pySim/exceptions.py10
-rw-r--r--pySim/transport/__init__.py4
2 files changed, 13 insertions, 1 deletions
diff --git a/pySim/exceptions.py b/pySim/exceptions.py
index 68303e1..e959a70 100644
--- a/pySim/exceptions.py
+++ b/pySim/exceptions.py
@@ -6,6 +6,7 @@
#
# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
+# Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -37,3 +38,12 @@ class ProtocolError(Exception):
class ReaderError(Exception):
pass
+
+class SwMatchError(Exception):
+ """Raised when an operation specifies an expected SW but the actual SW from
+ the card doesn't match."""
+ def __init__(self, sw_actual, sw_expected):
+ self.sw_actual = sw_actual
+ self.sw_expected = sw_expected
+ def __str__(self):
+ return "Received %s but expected %s from card" % (self.sw_actual, self.sw_expected)
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 69e2fe9..398c49f 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -4,6 +4,8 @@
""" pySim: PCSC reader transport link base
"""
+from pySim.exceptions import *
+
#
# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
#
@@ -101,5 +103,5 @@ class LinkBase(object):
sw_masked = sw_masked + rv[1][i].lower()
if sw.lower() != sw_masked:
- raise RuntimeError("SW match failed! Expected %s and got %s." % (sw.lower(), rv[1]))
+ raise SwMatchError(sw.lower(), rv[1])
return rv