-Bugfix: Erroneously set Lc and not Le for case 2 APDUs

-Added new property effective_Le 


git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@434 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
oepen
2011-07-25 21:59:34 +00:00
parent d3b7dd4dac
commit a98c1f84e7

View File

@@ -290,20 +290,24 @@ class C_APDU(APDU):
apdu = apdu + [0] * max(4-len(apdu), 0)
self.CLA, self.INS, self.P1, self.P2 = apdu[:4] # case 1, 2, 3, 4
self.__extended_length = False
if len(apdu) == 4: # case 1
self.data = ""
elif (len(apdu) >= 7) and (apdu[5] == 0): # extended length apdu
self.Lc = (apdu[5]<<8) + apdu[6]
self.__extended_length = True
if len(apdu) == 7: # case 2 extended length
self.data = ""
elif len(apdu) == 7 + self.Lc: # case 3 extended length
self.data = apdu[7:]
elif len(apdu) == 7 + self.Lc + 3: # case 4 extended length
self.data = apdu[7:-3]
self.Le = (apdu[-2]<<8) + apdu[-1]
else:
raise ValueError, "Invalid Lc value. Is %s, should be %s or %s" % (self.Lc,
7 + self.Lc, 7 + self.Lc + 3)
self.data = ""
else: # case 3, 4 extended length
self.Lc = (apdu[5]<<8) + apdu[6]
if len(apdu) == 7 + self.Lc: # case 3 extended length
self.data = apdu[7:]
elif len(apdu) == 7 + self.Lc + 3: # case 4 extended length
self.Le = (apdu[-2]<<8) + apdu[-1]
self.data = apdu[7:-3]
else:
raise ValueError, "Invalid Lc value. Is %s, should be %s or %s" % (self.Lc,
7 + self.Lc, 7 + self.Lc + 3)
else: # short apdu
if len(apdu) == 5: # case 2 short apdu
self.Le = apdu[-1]
@@ -315,9 +319,9 @@ class C_APDU(APDU):
elif len(apdu) == 5 + self.Lc + 1: # case 4
self.data = apdu[5:-1]
self.Le = apdu[-1]
else:
raise ValueError, "Invalid Lc value. Is %s, should be %s or %s" % (self.Lc,
5 + self.Lc, 5 + self.Lc + 1)
else:
raise ValueError, "Invalid Lc value. Is %s, should be %s or %s" % (self.Lc,
5 + self.Lc, 5 + self.Lc + 1)
CLA = _make_byte_property("CLA"); cla = CLA
INS = _make_byte_property("INS"); ins = INS
@@ -326,6 +330,16 @@ class C_APDU(APDU):
Lc = _make_byte_property("Lc"); lc = Lc
Le = _make_byte_property("Le"); le = Le
@property
def effective_Le(self):
if hasattr(self, "_Le") and (self.Le == 0):
if self.__extended_length:
return 0xffff
else:
return 0xff
else:
return self.Le
def _format_fields(self):
fields = ["CLA", "INS", "P1", "P2"]
if self.Lc > 0: