From fcfa5f12a4cd482973fdf03000af4a26a360dc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 2 Apr 2019 12:56:06 +0200 Subject: python: Expose the sha256() function in the utilities. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Damir Jelić --- python/tests/utils_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 python/tests/utils_test.py (limited to 'python/tests') diff --git a/python/tests/utils_test.py b/python/tests/utils_test.py new file mode 100644 index 0000000..a552d12 --- /dev/null +++ b/python/tests/utils_test.py @@ -0,0 +1,29 @@ +import base64 +import hashlib + +from future.utils import bytes_to_native_str +from hypothesis import given +from hypothesis.strategies import text + +from olm import sha256 +from olm._compat import to_bytes + + +class TestClass(object): + @given(text(), text()) + def test_sha256(self, input1, input2): + first_hash = sha256(input1) + second_hash = sha256(input2) + + hashlib_hash = base64.b64encode( + hashlib.sha256(to_bytes(input1)).digest() + ) + + hashlib_hash = bytes_to_native_str(hashlib_hash[:-1]) + + if input1 == input2: + assert first_hash == second_hash + else: + assert first_hash != second_hash + + assert hashlib_hash == first_hash -- cgit v1.2.3