def test_to_bytes(self): assert isinstance(to_bytes("a"), bytes) assert isinstance(to_bytes(u"a"), bytes) assert isinstance(to_bytes(b"a"), bytes) assert isinstance(to_bytes(r"a"), bytes) with pytest.raises(TypeError): to_bytes(0)
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
def test_sha256(self): input1 = "It's a secret to everybody" input2 = "It's a secret to nobody" 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]) assert first_hash != second_hash assert hashlib_hash == first_hash