Abstract out command class
This commit is contained in:
parent
e343352675
commit
144efe1cf7
|
@ -6,6 +6,7 @@ from utils import C_APDU, R_APDU
|
||||||
class ISO_Card(Card):
|
class ISO_Card(Card):
|
||||||
DRIVER_NAME = ["ISO"]
|
DRIVER_NAME = ["ISO"]
|
||||||
COMMAND_GET_RESPONSE = C_APDU(ins=0xc0)
|
COMMAND_GET_RESPONSE = C_APDU(ins=0xc0)
|
||||||
|
COMMAND_CLASS = C_APDU
|
||||||
|
|
||||||
APDU_VERIFY_PIN = C_APDU(ins=0x20)
|
APDU_VERIFY_PIN = C_APDU(ins=0x20)
|
||||||
|
|
||||||
|
|
|
@ -230,10 +230,13 @@ class Cyberflex_Shell(Shell):
|
||||||
self.card.last_delta = None
|
self.card.last_delta = None
|
||||||
|
|
||||||
def do_fancy_apdu(self, *args):
|
def do_fancy_apdu(self, *args):
|
||||||
"Parse and transmit a fancy APDU"
|
"Parse and transmit a fancy command"
|
||||||
apdu = None
|
apdu = None
|
||||||
try:
|
try:
|
||||||
apdu = utils.C_APDU.parse_fancy(*args)
|
if hasattr(self.card.COMMAND_CLASS, "parse_fancy"):
|
||||||
|
apdu = self.card.COMMAND_CLASS.parse_fancy(*args)
|
||||||
|
else:
|
||||||
|
apdu = self.card.COMMAND_CLASS(*args)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
5
utils.py
5
utils.py
|
@ -228,6 +228,11 @@ class Transmission_Frame(object):
|
||||||
# Stub for implementation in subclasses
|
# Stub for implementation in subclasses
|
||||||
# Semantics should be: c=a.append(b) <=> c.data == a.data + b.data and c.status == b.status
|
# Semantics should be: c=a.append(b) <=> c.data == a.data + b.data and c.status == b.status
|
||||||
append = None
|
append = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def parse_fancy(cls, *args):
|
||||||
|
argstring = "".join((" ".join(args)).split())
|
||||||
|
return cls(binascii.unhexlify(argstring))
|
||||||
|
|
||||||
class Command_Frame(Transmission_Frame):
|
class Command_Frame(Transmission_Frame):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue