Add raw command.

* Fix indentation
 * API CHANGE: do_raw_apdu() is now do_normal_apdu()
 * New do_raw_apdu() function to use the Raw_APDU() class, exported as "raw" command
This commit is contained in:
Henryk Plötz 2010-06-01 03:06:02 +02:00
parent 59917271dd
commit 9d5528a470
1 changed files with 14 additions and 2 deletions

View File

@ -218,7 +218,7 @@ class Cyberflex_Shell(Shell):
"Parse a fancy APDU and print the result"
apdu = utils.C_APDU.parse_fancy_apdu(*args)
data = apdu.render()
if hasattr(self, "card"):
if hasattr(self, "card"):
self.card.last_result = utils.R_APDU(data+"\x00\x00")
print utils.hexdump(data)
@ -230,6 +230,7 @@ class Cyberflex_Shell(Shell):
self.card.last_delta = None
def do_fancy_apdu(self, *args):
"Parse and transmit a fancy APDU"
apdu = None
try:
apdu = utils.C_APDU.parse_fancy_apdu(*args)
@ -239,7 +240,8 @@ class Cyberflex_Shell(Shell):
if apdu is not None:
return self.do_apdu(apdu)
def do_raw_apdu(self, *args):
def do_normal_apdu(self, *args):
"Transmit an APDU"
apdu_string = "".join(args)
if not utils.C_APDU._apduregex.match(apdu_string):
raise NotImplementedError
@ -249,6 +251,15 @@ class Cyberflex_Shell(Shell):
return self.do_apdu(apdu)
def do_raw_apdu(self, *args):
"Transmit a raw data string as an APDU"
apdu_string = "".join(args)
apdu_binary = binascii.a2b_hex("".join(apdu_string.split()))
apdu = utils.Raw_APDU(apdu_binary)
return self.do_apdu(apdu)
def do_apdu(self, apdu):
response = self.card.send_apdu(apdu)
@ -381,6 +392,7 @@ class Cyberflex_Shell(Shell):
"reconnect": cmd_reconnect,
"driver_load": cmd_loaddriver,
"driver_unload": cmd_unloaddriver,
"raw": do_raw_apdu,
"run_script": cmd_runscript,
}