aboutsummaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
authorhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-05-17 18:40:12 +0000
committerhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-05-17 18:40:12 +0000
commita2d6c6a624c0e02fd9cf1309c87b9dfae3640541 (patch)
treed0698c6f9894fef4c26a19cca76130fe7855896b /utils.py
parentdf4e90ea9e1d123453ebe4a302b2313c0f330a3c (diff)
better handling of non-T=0 APDUs. may still be buggy
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@46 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py58
1 files changed, 32 insertions, 26 deletions
diff --git a/utils.py b/utils.py
index 2f6471a..a590d09 100644
--- a/utils.py
+++ b/utils.py
@@ -142,27 +142,30 @@ class APDU:
lc_was_set = False
- if len(initbuff) == 4: ## ISO case 1
- self.le = 0
- self.lc = 0
- self.content = list()
- elif len(initbuff) == 5: ## ISO case 2
- self.le = initbuff[self.OFFSET_LE]
- self.lc = 0
- self.content = list()
- elif len(initbuff) > 5:
- self.lc = initbuff[self.OFFSET_LC]
- lc_was_set = True
- if len(initbuff) == 5 + self.lc: ## ISO case 3
- self.le = 0
- self.content = initbuff[5:5+self.lc]
- elif len(initbuff) == 5 + self.lc + 1: ## ISO case 4
- self.le = initbuff[-1]
- self.content = initbuff[5:5+self.lc]
- else:
- raise ValueError, "Invalid APDU, length(%i) != 4 + 1 + lc(%i) + 1" % (len(initbuff), self.lc)
- else:
- raise ValueError, "Invalid APDU, impossible"
+## if len(initbuff) == 4: ## ISO case 1
+## self.le = 0
+## self.lc = 0
+## self.content = list()
+## elif len(initbuff) == 5: ## ISO case 2
+## self.le = initbuff[self.OFFSET_LE]
+## self.lc = 0
+## self.content = list()
+## elif len(initbuff) > 5:
+## self.lc = initbuff[self.OFFSET_LC]
+## lc_was_set = True
+## if len(initbuff) == 5 + self.lc: ## ISO case 3
+## self.le = 0
+## self.content = initbuff[5:5+self.lc]
+## elif len(initbuff) == 5 + self.lc + 1: ## ISO case 4
+## self.le = initbuff[-1]
+## self.content = initbuff[5:5+self.lc]
+## else:
+## raise ValueError, "Invalid APDU, length(%i) != 4 + 1 + lc(%i) + 1" % (len(initbuff), self.lc)
+## else:
+## raise ValueError, "Invalid APDU, impossible"
+ self.le = 0
+ self.lc = len(initbuff)-4
+ self.content = initbuff[4:]
for (kw_orig, arg) in kwargs.items():
kw = kw_orig.lower()
@@ -255,13 +258,16 @@ class APDU:
else:
self.__dict__[name] = value
- def get_string(self):
+ def get_string(self, protocol=0):
"""Return the contents of this APDU as a binary string."""
contents = [self.cla, self.ins, self.p1, self.p2]
- if self.lc > 0:
- contents.extend( [self.lc] + self.content)
- if self.le > 0:
- contents.append( self.le )
+ if protocol == 0:
+ if self.lc > 0:
+ contents.extend( [self.lc] + self.content)
+ if self.le > 0:
+ contents.append( self.le )
+ else:
+ contents.extend( self.content )
return "".join([i is not None and chr(i) or "?" for i in contents])
if __name__ == "__main__":