aboutsummaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
authorhenryk <henryk@f711b948-2313-0410-aaa9-d29f33439f0b>2005-09-30 03:34:15 +0000
committerhenryk <henryk@f711b948-2313-0410-aaa9-d29f33439f0b>2005-09-30 03:34:15 +0000
commit82eab03c687907924e5e4a0188e4c1ff61642a03 (patch)
tree44bb85cb7f179d95416d5605a00d082b5439d68e /utils.py
parentb89286679ba48cef0bd3b0dc1111176df7c871b5 (diff)
fixex
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@25 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/utils.py b/utils.py
index 98e5823..08a2031 100644
--- a/utils.py
+++ b/utils.py
@@ -107,7 +107,7 @@ class APDU(list):
Note: only set the le parameter if you don't send data."""
if len(args) == 1 and type(args[0]) == APDU:
- self.extend(args)
+ self.extend(args[0])
else:
for arg in args:
if type(arg) == str:
@@ -123,6 +123,8 @@ class APDU(list):
if len(self) < 4:
self.extend([0] * (4-len(self)))
+ if len(self) < self.OFFSET_LC+1:
+ self[self.OFFSET_LC:self.OFFSET_LC+1] = [None]
le = None
for (kw, arg) in kwargs.items():
@@ -152,7 +154,10 @@ class APDU(list):
self[self.OFFSET_LE:self.OFFSET_LE+1] = (le,)
if self[self.OFFSET_LC] == None:
- self[self.OFFSET_LC] = len(self)-self.OFFSET_CONTENT
+ if len(self) > self.OFFSET_CONTENT:
+ self[self.OFFSET_LC] = len(self)-self.OFFSET_CONTENT
+ else:
+ del self[self.OFFSET_LC]
for i in range(len(self)):
t = type(self[i])
@@ -188,7 +193,7 @@ class APDU(list):
return result
def get_string(self):
- return [chr(i) for i in self]
+ return "".join([i is not None and chr(i) or "?" for i in self])
if __name__ == "__main__":
response = """
@@ -242,5 +247,6 @@ if __name__ == "__main__":
#parse_status(_unformat_hexdump(response)[:-2])
print APDU((1,2,3), cla=0x23, content="hallo", lc=None)
+ print APDU(1,2,3,4,None,4,6)