path: root/utils.py
diff options
authorHenryk Plötz <henryk@ploetzli.ch>2010-03-03 05:28:48 +0100
committerHenryk Plötz <henryk@ploetzli.ch>2010-03-03 05:28:48 +0100
commit9fbc745bd0fde9bf5a3d3406cacde474309fa84e (patch)
tree28b9c962126b543e174e8bd32ed70b72ae5fd43c /utils.py
parent41bb2396b6c575885830869dc4cb441c24f1ca27 (diff)
Change behavior of defaults, possible API CHANGE, hope it's not too intrusive
+ Change R_APDU parser and data default to allow construction of empty R_APDUs + Default unspecified C_APDU fields to None instead of 0, makes distinction of Le=0 vs. Le not present externally visible
Diffstat (limited to 'utils.py')
1 files changed, 5 insertions, 2 deletions
diff --git a/utils.py b/utils.py
index 89245d1..51c139b 100644
--- a/utils.py
+++ b/utils.py
@@ -124,7 +124,7 @@ def _unformat_hexdump(dump):
def _make_byte_property(prop):
"Make a byte property(). This is meta code."
- return property(lambda self: getattr(self, "_"+prop, getattr(self, "_DEFAULT_"+prop, 0)),
+ return property(lambda self: getattr(self, "_"+prop, getattr(self, "_DEFAULT_"+prop, None)),
lambda self, value: self._setbyte(prop, value),
lambda self: delattr(self, "_"+prop),
"The %s attribute of the APDU" % prop)
@@ -177,7 +177,7 @@ class APDU(object):
setattr(self, name, value)
def _getdata(self):
- return getattr(self, "_data", [])
+ return getattr(self, "_data", "")
def _setdata(self, value):
if isinstance(value, str):
self._data = "".join([e for e in value])
@@ -444,6 +444,9 @@ class R_APDU(APDU):
def parse(self, apdu):
"Parse a full response APDU and assign the values to our object, overwriting whatever there was."
+ if len(apdu) == 0: # To be filled in later
+ return
self.SW = apdu[-2:]
self.data = apdu[:-2]