mirror of https://gerrit.osmocom.org/pysim
pySim-shell: match SW in apdu command
The apdu command has no option to match the resulting SW. Lets add a new option for this. Change-Id: Ic5a52d7cf533c51d111850eb6d8147011a48ae6c
This commit is contained in:
parent
7226c09569
commit
e7d1b67d80
|
@ -40,7 +40,7 @@ from pySim.exceptions import *
|
||||||
from pySim.commands import SimCardCommands
|
from pySim.commands import SimCardCommands
|
||||||
from pySim.transport import init_reader, ApduTracer, argparse_add_reader_args
|
from pySim.transport import init_reader, ApduTracer, argparse_add_reader_args
|
||||||
from pySim.cards import card_detect, SimCard
|
from pySim.cards import card_detect, SimCard
|
||||||
from pySim.utils import h2b, swap_nibbles, rpad, b2h, h2s, JsonEncoder, bertlv_parse_one
|
from pySim.utils import h2b, swap_nibbles, rpad, b2h, h2s, JsonEncoder, bertlv_parse_one, sw_match
|
||||||
from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex, boxed_heading_str
|
from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex, boxed_heading_str
|
||||||
from pySim.card_handler import CardHandler, CardHandlerAuto
|
from pySim.card_handler import CardHandler, CardHandlerAuto
|
||||||
|
|
||||||
|
@ -246,6 +246,7 @@ class PysimApp(cmd2.Cmd):
|
||||||
|
|
||||||
apdu_cmd_parser = argparse.ArgumentParser()
|
apdu_cmd_parser = argparse.ArgumentParser()
|
||||||
apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string')
|
apdu_cmd_parser.add_argument('APDU', type=str, help='APDU as hex string')
|
||||||
|
apdu_cmd_parser.add_argument('--expect-sw', help='expect a specified status word', type=str, default=None)
|
||||||
|
|
||||||
@cmd2.with_argparser(apdu_cmd_parser)
|
@cmd2.with_argparser(apdu_cmd_parser)
|
||||||
def do_apdu(self, opts):
|
def do_apdu(self, opts):
|
||||||
|
@ -258,6 +259,9 @@ class PysimApp(cmd2.Cmd):
|
||||||
self.poutput("SW: %s, RESP: %s" % (sw, data))
|
self.poutput("SW: %s, RESP: %s" % (sw, data))
|
||||||
else:
|
else:
|
||||||
self.poutput("SW: %s" % sw)
|
self.poutput("SW: %s" % sw)
|
||||||
|
if opts.expect_sw:
|
||||||
|
if not sw_match(sw, opts.expect_sw):
|
||||||
|
raise SwMatchError(sw, opts.expect_sw)
|
||||||
|
|
||||||
class InterceptStderr(list):
|
class InterceptStderr(list):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Reference in New Issue