2019-04-02 12:56:06 +02:00
|
|
|
import base64
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
from future.utils import bytes_to_native_str
|
|
|
|
|
|
|
|
from olm import sha256
|
|
|
|
from olm._compat import to_bytes
|
|
|
|
|
|
|
|
|
|
|
|
class TestClass(object):
|
2019-06-20 13:45:33 +02:00
|
|
|
def test_sha256(self):
|
|
|
|
input1 = "It's a secret to everybody"
|
|
|
|
input2 = "It's a secret to nobody"
|
|
|
|
|
2019-04-02 12:56:06 +02:00
|
|
|
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])
|
|
|
|
|
2019-06-20 13:54:25 +02:00
|
|
|
assert first_hash != second_hash
|
2019-04-02 12:56:06 +02:00
|
|
|
assert hashlib_hash == first_hash
|