From: Martin Willi Date: Tue, 8 Dec 2015 16:13:59 +0000 (+0100) Subject: vici: Explicitly set the Python encoding type X-Git-Tag: 5.5.2dr5~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=22f08609f1b6;p=thirdparty%2Fstrongswan.git vici: Explicitly set the Python encoding type When using vici over RPyC and its (awesome) splitbrain, encoding and decoding strings fails in vici, most likely because of the Monkey-Patch magic splitbrain uses. When specifying the implicit UTF-8 as encoding scheme explicitly, Python uses the correct method to encode/decode the string, making vici useable in splitbrain contexts. --- diff --git a/src/libcharon/plugins/vici/python/vici/protocol.py b/src/libcharon/plugins/vici/python/vici/protocol.py index 880d3343c4..919231d439 100644 --- a/src/libcharon/plugins/vici/python/vici/protocol.py +++ b/src/libcharon/plugins/vici/python/vici/protocol.py @@ -62,7 +62,7 @@ class Packet(object): @classmethod def _named_request(cls, request_type, request, message=None): - request = request.encode() + requestdata = request.encode("UTF-8") payload = struct.pack("!BB", request_type, len(request)) + request if message is not None: return payload + message @@ -105,12 +105,12 @@ class Message(object): @classmethod def serialize(cls, message): def encode_named_type(marker, name): - name = name.encode() + name = name.encode("UTF-8") return struct.pack("!BB", marker, len(name)) + name def encode_blob(value): if not isinstance(value, bytes): - value = str(value).encode() + value = str(value).encode("UTF-8") return struct.pack("!H", len(value)) + value def serialize_list(lst): @@ -147,7 +147,7 @@ class Message(object): def deserialize(cls, stream): def decode_named_type(stream): length, = struct.unpack("!B", stream.read(1)) - return stream.read(length).decode() + return stream.read(length).decode("UTF-8") def decode_blob(stream): length, = struct.unpack("!H", stream.read(2))