aboutsummaryrefslogtreecommitdiff
path: root/python/olm/_compat.py
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2018-10-16 00:31:56 -0400
committerHubert Chathi <hubert@uhoreg.ca>2018-10-16 00:31:56 -0400
commit5ef6a844d6fd3d58d1eb85dcd188ac6b6baa3fbe (patch)
tree267b23b74f57cc1d017dea8b844e318201fb5db9 /python/olm/_compat.py
parent357d4ff4795d89d623663b3996ddd2dfd4990971 (diff)
overwrite buffers that may contain sensitive data
also reduce the amount of memory copying that we do
Diffstat (limited to 'python/olm/_compat.py')
-rw-r--r--python/olm/_compat.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/python/olm/_compat.py b/python/olm/_compat.py
index 8f1670d..91e4d1b 100644
--- a/python/olm/_compat.py
+++ b/python/olm/_compat.py
@@ -26,6 +26,16 @@ except ImportError: # pragma: no cover
URANDOM = urandom # type: ignore
+def to_bytearray(string):
+ # type: (AnyStr) -> bytes
+ if isinstance(string, bytes):
+ return bytearray(string)
+ elif isinstance(string, str):
+ return bytearray(string, "utf-8")
+
+ raise TypeError("Invalid type {}".format(type(string)))
+
+
def to_bytes(string):
# type: (AnyStr) -> bytes
if isinstance(string, bytes):