aboutsummaryrefslogtreecommitdiff
path: root/python/tests/utils_test.py
blob: a552d125000c72741270f610a5266754f5b25655 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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