blob: 4fb8f72af89052442588d00f4d2494c582ce6302 [file] [log] [blame]
Sylvain Munaut76504e02010-12-07 00:24:32 +01001# -*- coding: utf-8 -*-
2
3""" pySim: Exceptions
4"""
5
6#
7# Copyright (C) 2009-2010 Sylvain Munaut <tnt@246tNt.com>
Harald Weltee79cc802021-01-21 14:10:43 +01008# Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
Sylvain Munaut76504e02010-12-07 00:24:32 +01009#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23
Denis 'GNUtoo' Carikli8902bcd2019-09-12 15:03:23 +020024class NoCardError(Exception):
Sylvain Munaut76504e02010-12-07 00:24:32 +010025 pass
Vadim Yanitskiy1381ff12018-10-27 01:48:15 +070026
Denis 'GNUtoo' Carikli8902bcd2019-09-12 15:03:23 +020027class ProtocolError(Exception):
28 pass
29
30class ReaderError(Exception):
Vadim Yanitskiy1381ff12018-10-27 01:48:15 +070031 pass
Harald Weltee79cc802021-01-21 14:10:43 +010032
33class SwMatchError(Exception):
34 """Raised when an operation specifies an expected SW but the actual SW from
35 the card doesn't match."""
Harald Welteb2edd142021-01-08 23:29:35 +010036 def __init__(self, sw_actual, sw_expected, rs=None):
Harald Weltee79cc802021-01-21 14:10:43 +010037 self.sw_actual = sw_actual
38 self.sw_expected = sw_expected
Harald Welteb2edd142021-01-08 23:29:35 +010039 self.rs = rs
Harald Weltee79cc802021-01-21 14:10:43 +010040 def __str__(self):
Harald Welteb2edd142021-01-08 23:29:35 +010041 if self.rs:
Vadim Yanitskiy3b51f432021-03-12 02:18:06 +010042 r = self.rs.interpret_sw(self.sw_actual)
Harald Welteb2edd142021-01-08 23:29:35 +010043 if r:
44 return "SW match failed! Expected %s and got %s: %s - %s" % (self.sw_expected, self.sw_actual, r[0], r[1])
Harald Weltee79cc802021-01-21 14:10:43 +010045 return "SW match failed! Expected %s and got %s." % (self.sw_expected, self.sw_actual)