Bugfixing and code style improvements

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@461 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
oepen
2011-07-29 18:25:30 +00:00
parent 65a8acaae3
commit 7ada4a0ca5

View File

@@ -19,23 +19,24 @@
import TLVutils
from time import time
from random import seed, randint
from virtualsmartcard.ConstantDefinitions import CRT_TEMPLATE
from virtualsmartcard.utils import inttostring, stringtoint
from virtualsmartcard.SWutils import *
from virtualsmartcard.ConstantDefinitions import CRT_TEMPLATE, ALGO_MAPPING
from virtualsmartcard.utils import inttostring
from virtualsmartcard.SWutils import SwError, SW
class ControlReferenceTemplate:
def __init__(self,type,config=""):
def __init__(self, tag, config=""):
"""
Generates a new CRT
@param type: Type of the CRT (HT, AT, KT, CCT, DST, CT-sym, CT-asym)
@param config: A string containing TLV encoded Security Environment parameters
@param config: A string containing TLV encoded Security Environment
parameters
"""
if type not in (CRT_TEMPLATE["AT"], CRT_TEMPLATE["HT"],
if tag not in (CRT_TEMPLATE["AT"], CRT_TEMPLATE["HT"],
CRT_TEMPLATE["KAT"], CRT_TEMPLATE["CCT"],
CRT_TEMPLATE["DST"], CRT_TEMPLATE["CT"]):
raise ValueError, "Unknown control reference tag."
else:
self.type = type
self.type = tag
self.iv = None
self.keyref = None
@@ -51,8 +52,8 @@ class ControlReferenceTemplate:
def parse_SE_config(self, config):
structure = TLVutils.unpack(config)
for object in structure:
tag, length, value = object
for tlv in structure:
tag, length, value = tlv
if tag == 0x80:
self.__set_algo(value)
elif tag in (0x81, 0x82, 0x83, 0x84):
@@ -60,7 +61,7 @@ class ControlReferenceTemplate:
elif tag in range(0x85, 0x93):
self.__set_iv(tag, length, value)
elif tag == 0x95:
self.usage_qualifier = data
self.usage_qualifier = value
def __set_algo(self, data):
if not ALGO_MAPPING.has_key(data):
@@ -108,9 +109,12 @@ class ControlReferenceTemplate:
while self.__config_string[position:position+1] != tag and position < len(self.__config_string):
length = inttostring(self.__config_string[position+1:position+2])
position += length + 3
if position < len(self.__config_string): #Replace Tag
length = inttostring(self.__config_string[position+1:position+2])
self.__config_string = self.__config_string[:position] + tag + inttostring(len(data)) + data + self.__config_string[position+2+length:]
self.__config_string = self.__config_string[:position] + tag +\
inttostring(len(data)) + data +\
self.__config_string[position+2+length:]
else: #Add new tag
self.__config_string += tag + inttostring(len(data)) + data