Merge pull request #180 from betawave/str-bytes-conversion-fix

enable msg to be either string or bytes
This commit is contained in:
Frank Morgner
2020-10-27 11:05:36 +01:00
committed by GitHub
2 changed files with 5 additions and 2 deletions

View File

@@ -504,7 +504,7 @@ class VirtualICC(object):
def __sendToVPICC(self, msg):
""" Send a message to the vpcd """
if isinstance(msg, str):
self.sock.sendall(struct.pack('!H', len(msg)) + msg.encode())
self.sock.sendall(struct.pack('!H', len(msg)) + bytes(map(ord,msg)))
else:
self.sock.sendall(struct.pack('!H', len(msg)) + msg)

View File

@@ -114,7 +114,10 @@ class RelayOS(SmartcardOS):
def execute(self, msg):
# sendCommandAPDU() expects a list of APDU bytes
apdu = map(ord, msg)
if isinstance(msg,str):
apdu = map(ord, msg)
else:
apdu = list(msg)
try:
rapdu, sw1, sw2 = self.session.sendCommandAPDU(apdu)