Skip to content

Commit

Permalink
Abstract out command class
Browse files Browse the repository at this point in the history
  • Loading branch information
henryk committed Oct 18, 2010
1 parent e343352 commit 144efe1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions cards/iso_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class ISO_Card(Card):
DRIVER_NAME = ["ISO"]
COMMAND_GET_RESPONSE = C_APDU(ins=0xc0)
COMMAND_CLASS = C_APDU

APDU_VERIFY_PIN = C_APDU(ins=0x20)

Expand Down
7 changes: 5 additions & 2 deletions cyberflex-shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,13 @@ def _clear_sw(self):
self.card.last_delta = None

def do_fancy_apdu(self, *args):
"Parse and transmit a fancy APDU"
"Parse and transmit a fancy command"
apdu = None
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:
raise NotImplementedError

Expand Down
5 changes: 5 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ def __repr__(self):
# Stub for implementation in subclasses
# Semantics should be: c=a.append(b) <=> c.data == a.data + b.data and c.status == b.status
append = None

@classmethod
def parse_fancy(cls, *args):
argstring = "".join((" ".join(args)).split())
return cls(binascii.unhexlify(argstring))

class Command_Frame(Transmission_Frame):
pass
Expand Down

0 comments on commit 144efe1

Please sign in to comment.