Code style improvements

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@470 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
oepen
2011-07-30 12:23:23 +00:00
parent 24c858eba6
commit c908fa9436

View File

@@ -16,18 +16,14 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# virtualsmartcard. If not, see <http://www.gnu.org/licenses/>. # virtualsmartcard. If not, see <http://www.gnu.org/licenses/>.
# #
from virtualsmartcard.ConstantDefinitions import *
from virtualsmartcard.TLVutils import *
from virtualsmartcard.SWutils import SwError, SW
from virtualsmartcard.SmartcardFilesystem import prettyprint_anything, MF, DF, CryptoflexMF, TransparentStructureEF, make_property
from virtualsmartcard.utils import C_APDU, R_APDU, hexdump, inttostring
from virtualsmartcard.SmartcardSAM import SAM, PassportSAM, CryptoflexSAM
import CardGenerator
from smartcard.CardMonitoring import CardMonitor, CardObserver
from pickle import dumps, loads from virtualsmartcard.ConstantDefinitions import MAX_EXTENDED_LE, MAX_SHORT_LE
import socket, struct, sys, signal, atexit, traceback from virtualsmartcard.SWutils import SwError, SW
import struct, getpass, anydbm from virtualsmartcard.SmartcardFilesystem import make_property
from virtualsmartcard.utils import C_APDU, R_APDU, hexdump, inttostring
import CardGenerator
import socket, struct, sys, signal, atexit, smartcard
class SmartcardOS(object): # {{{ class SmartcardOS(object): # {{{
@@ -350,13 +346,15 @@ class CryptoflexOS(Iso7816OS): # {{{
# cryptoflex does not inpterpret le==0 as maxle # cryptoflex does not inpterpret le==0 as maxle
self.lastCommandSW = sw self.lastCommandSW = sw
self.lastCommandOffcut = data self.lastCommandOffcut = data
r = R_APDU(inttostring(SW["ERR_WRONGLENGTH"] + min(0xff,len(data)))).render() r = R_APDU(inttostring(SW["ERR_WRONGLENGTH"] +\
min(0xff, len(data)))).render()
else: else:
if ins == 0xa4 and len(data): if ins == 0xa4 and len(data):
# get response should be followed by select file # get response should be followed by select file
self.lastCommandSW = sw self.lastCommandSW = sw
self.lastCommandOffcut = data self.lastCommandOffcut = data
r = R_APDU(inttostring(SW["NORMAL_REST"] + min(0xff, len(data)))).render() r = R_APDU(inttostring(SW["NORMAL_REST"] +\
min(0xff, len(data)))).render()
else: else:
r = Iso7816OS.formatResult(self, le, data, sw, False) r = Iso7816OS.formatResult(self, le, data, sw, False)
@@ -366,7 +364,6 @@ class CryptoflexOS(Iso7816OS): # {{{
class RelayOS(SmartcardOS): # {{{ class RelayOS(SmartcardOS): # {{{
def __init__(self, readernum): def __init__(self, readernum):
import smartcard
readers = smartcard.System.listReaders() readers = smartcard.System.listReaders()
if len(readers) <= readernum: if len(readers) <= readernum:
print "Invalid number of reader '%u' (only %u available)" % (readernum, len(readers)) print "Invalid number of reader '%u' (only %u available)" % (readernum, len(readers))
@@ -388,14 +385,12 @@ class RelayOS(SmartcardOS): # {{{
atexit.register(self.cleanup) atexit.register(self.cleanup)
def cleanup(self): def cleanup(self):
import smartcard
try: try:
self.session.close() self.session.close()
except smartcard.Exceptions.CardConnectionException, e: except smartcard.Exceptions.CardConnectionException, e:
print "Error disconnecting from card: %s" % e.message print "Error disconnecting from card: %s" % e.message
def getATR(self): def getATR(self):
import smartcard
try: try:
atr = self.session.getATR() atr = self.session.getATR()
except smartcard.Exceptions.CardConnectionException, e: except smartcard.Exceptions.CardConnectionException, e:
@@ -410,7 +405,6 @@ class RelayOS(SmartcardOS): # {{{
return "".join([chr(b) for b in atr]) return "".join([chr(b) for b in atr])
def powerUp(self): def powerUp(self):
import smartcard
try: try:
self.session.getATR() self.session.getATR()
except smartcard.Exceptions.CardConnectionException, e: except smartcard.Exceptions.CardConnectionException, e:
@@ -421,7 +415,6 @@ class RelayOS(SmartcardOS): # {{{
sys.exit() sys.exit()
def powerDown(self): def powerDown(self):
import smartcard
try: try:
self.session.close() self.session.close()
except smartcard.Exceptions.CardConnectionException, e: except smartcard.Exceptions.CardConnectionException, e:
@@ -434,7 +427,6 @@ class RelayOS(SmartcardOS): # {{{
for b in msg: for b in msg:
apdu.append(ord(b)) apdu.append(ord(b))
import smartcard
try: try:
rapdu, sw1, sw2 = self.session.sendCommandAPDU(apdu) rapdu, sw1, sw2 = self.session.sendCommandAPDU(apdu)
except smartcard.Exceptions.CardConnectionException, e: except smartcard.Exceptions.CardConnectionException, e: