The __replace_tag function was completely broken. It is now somewhat fixed, but

should still be replaced by a more elegant solution.


git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@483 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
oepen
2011-08-08 12:20:31 +00:00
parent 227b684db8
commit d8a1703c6d

View File

@@ -20,7 +20,7 @@ import TLVutils
from time import time from time import time
from random import seed, randint from random import seed, randint
from virtualsmartcard.ConstantDefinitions import CRT_TEMPLATE, ALGO_MAPPING from virtualsmartcard.ConstantDefinitions import CRT_TEMPLATE, ALGO_MAPPING
from virtualsmartcard.utils import inttostring from virtualsmartcard.utils import inttostring, stringtoint
from virtualsmartcard.SWutils import SwError, SW from virtualsmartcard.SWutils import SwError, SW
class ControlReferenceTemplate: class ControlReferenceTemplate:
@@ -81,10 +81,10 @@ class ControlReferenceTemplate:
to support new or different algorithms. to support new or different algorithms.
@param data: reference to an algorithm @param data: reference to an algorithm
""" """
if not ALGO_MAPPING.has_key(data): if not ALGO_MAPPING.has_key(data):
raise SwError(SW["ERR_REFNOTUSABLE"]) raise SwError(SW["ERR_REFNOTUSABLE"])
else: else:
#TODO: Sanity checking
self.algorithm = ALGO_MAPPING[data] self.algorithm = ALGO_MAPPING[data]
self.__replace_tag(0x80, data) self.__replace_tag(0x80, data)
@@ -129,16 +129,16 @@ class ControlReferenceTemplate:
""" """
position = 0 position = 0
while self.__config_string[position:position+1] != tag and position < len(self.__config_string): while self.__config_string[position:position+1] != tag and position < len(self.__config_string):
length = inttostring(self.__config_string[position+1:position+2]) length = stringtoint(self.__config_string[position+1:position+2])
position += length + 3 position += length + 3
if position < len(self.__config_string): #Replace Tag if position < len(self.__config_string): #Replace Tag
length = inttostring(self.__config_string[position+1:position+2]) length = stringtoint(self.__config_string[position+1:position+2])
self.__config_string = self.__config_string[:position] + tag +\ self.__config_string = self.__config_string[:position] +\
inttostring(len(data)) + data +\ chr(tag) + inttostring(len(data)) + data +\
self.__config_string[position+2+length:] self.__config_string[position+2+length:]
else: #Add new tag else: #Add new tag
self.__config_string += tag + inttostring(len(data)) + data self.__config_string += chr(tag) + inttostring(len(data)) + data
def to_string(self): def to_string(self):
""" """