Commit 6581f2c5 authored by oroulet's avatar oroulet

fix suspect line in encoding and fix (small) errors it was hiding

parent 02b764c9
......@@ -412,7 +412,7 @@ class Client(object):
challenge += self.security_policy.server_certificate
if self._server_nonce is not None:
challenge += self._server_nonce
params.ClientSignature.Algorithm = b"http://www.w3.org/2000/09/xmldsig#rsa-sha1"
params.ClientSignature.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
params.ClientSignature.Signature = self.security_policy.asymmetric_cryptography.signature(challenge)
params.LocaleIds.append("en")
if not username and not certificate:
......@@ -435,7 +435,7 @@ class Client(object):
# the last serverNonce to the serverCertificate
sig = uacrypto.sign_sha1(self.user_private_key, challenge)
params.UserTokenSignature = ua.SignatureData()
params.UserTokenSignature.Algorithm = b"http://www.w3.org/2000/09/xmldsig#rsa-sha1"
params.UserTokenSignature.Algorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
params.UserTokenSignature.Signature = sig
def _add_user_auth(self, params, username, password):
......
......@@ -85,7 +85,7 @@ class EventGenerator(object):
"""
Trigger the event. This will send a notification to all subscribed clients
"""
self.event.EventId = ua.Variant(uuid.uuid4().hex, ua.VariantType.ByteString)
self.event.EventId = ua.Variant(uuid.uuid4().hex.encode('utf-8'), ua.VariantType.ByteString)
if time:
self.event.Time = time
else:
......
......@@ -48,17 +48,20 @@ class _DateTime(object):
class _String(object):
@staticmethod
def pack(string):
if string is None:
return Primitives.Int32.pack(-1)
if isinstance(string, unicode):
string = string.encode('utf-8')
length = len(string)
return Primitives.Int32.pack(length) + string
if string is not None:
if sys.version_info.major > 2:
string = string.encode('utf-8')
else:
# we do not want this test to happen with python3
if isinstance(string, unicode):
string = string.encode('utf-8')
return _Bytes.pack(string)
@staticmethod
def unpack(data):
b = _Bytes.unpack(data)
if sys.version_info.major < 3:
# return unicode(b)
return b
else:
if b is None:
......@@ -69,7 +72,12 @@ class _String(object):
class _Bytes(object):
@staticmethod
def pack(data):
return _String.pack(data)
if data is None:
return Primitives.Int32.pack(-1)
length = len(data)
if not isinstance(data, bytes):
print("BYTES EXPECTED", type(Primitives.Int32.pack(length)), type(data), data)
return Primitives.Int32.pack(length) + data
@staticmethod
def unpack(data):
......@@ -142,7 +150,7 @@ class _Primitive1(object):
return None
if length == 0:
return ()
return struct.unpack(self._fmt.format(length), data.read(self.size*length))
return struct.unpack(self._fmt.format(length), data.read(self.size * length))
class Primitives1(object):
......@@ -258,7 +266,7 @@ def to_binary(uatype, val):
Pack a python object to binary given a string defining its type
"""
if uatype.startswith("ListOf"):
#if isinstance(val, (list, tuple)):
#if isinstance(val, (list, tuple)):
return list_to_binary(uatype[6:], val)
elif isinstance(uatype, (str, unicode)) and hasattr(ua.VariantType, uatype):
vtype = getattr(ua.VariantType, uatype)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment