aboutsummaryrefslogtreecommitdiff
path: root/python/olm/group_session.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2019-06-22 17:06:02 +0000
committerMatthew Hodgson <matthew@matrix.org>2019-06-22 17:06:02 +0000
commitae38f2c5a0db711ef573276bc745ee2384a197fa (patch)
tree6029aafbda99fe85c3fac43db2646b446d564917 /python/olm/group_session.py
parent25662564d415b9d5486f1915c9d46e5851b058d0 (diff)
parent61175c969b1de3ecd8c25478c69d6d1883dfa211 (diff)
Merge branch 'python/unicode_decode_errors' into 'master'
Python unicode decode errors when decrypting. See merge request matrix-org/olm!4
Diffstat (limited to 'python/olm/group_session.py')
-rw-r--r--python/olm/group_session.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/python/olm/group_session.py b/python/olm/group_session.py
index 737d9ef..5068192 100644
--- a/python/olm/group_session.py
+++ b/python/olm/group_session.py
@@ -33,7 +33,7 @@ from future.utils import bytes_to_native_str
# pylint: disable=no-name-in-module
from _libolm import ffi, lib # type: ignore
-from ._compat import URANDOM, to_bytearray, to_bytes
+from ._compat import URANDOM, to_bytearray, to_bytes, to_unicode_str
from ._finalize import track_for_finalization
@@ -176,8 +176,8 @@ class InboundGroupSession(object):
raise OlmGroupSessionError(last_error)
- def decrypt(self, ciphertext):
- # type: (AnyStr) -> Tuple[str, int]
+ def decrypt(self, ciphertext, unicode_errors="replace"):
+ # type: (AnyStr, str) -> Tuple[str, int]
"""Decrypt a message
Returns a tuple of the decrypted plain-text and the message index of
@@ -197,6 +197,13 @@ class InboundGroupSession(object):
Args:
ciphertext(str): Base64 encoded ciphertext containing the encrypted
message
+ unicode_errors(str, optional): The error handling scheme to use for
+ unicode decoding errors. The default is "replace" meaning that
+ the character that was unable to decode will be replaced with
+ the unicode replacement character (U+FFFD). Other possible
+ values are "strict", "ignore" and "xmlcharrefreplace" as well
+ as any other name registered with codecs.register_error that
+ can handle UnicodeEncodeErrors.
"""
if not ciphertext:
raise ValueError("Ciphertext can't be empty.")
@@ -223,10 +230,10 @@ class InboundGroupSession(object):
self._check_error(plaintext_length)
- plaintext = bytes_to_native_str(ffi.unpack(
- plaintext_buffer,
- plaintext_length
- ))
+ plaintext = to_unicode_str(
+ ffi.unpack(plaintext_buffer, plaintext_length),
+ errors=unicode_errors
+ )
# clear out copies of the plaintext
lib.memset(plaintext_buffer, 0, max_plaintext_length)