def test_hashing_base64(): args = [{ "data": "sample_data".encode('utf8'), "b64": "c2FtcGxlX2RhdGG8Ktkc" }] for a in args: assert a.get("b64") == hashing._base64_encode(a.get("data")) assert a.get("data") == hashing._base64_decode(a.get("b64")) args = [None, "", "abcdzz", "c2FtcGxlX2RhdGG8Ktka"] for a in args: with raises(ValueError): hashing._base64_decode(a)
def test_signing_is_signature_valid(): sg_ae = "sg_6cXUU8rimh8B3byLHJA9SaG29uRggtyrpGi5YAFiL9cJUoVtMX4P4kpd4UPTjiGXYSaquSN3gidJ73U8CtfweQ14GFgsC" account_id = "ak_axjxzUJpj9siJDQKZrBFNTvQLR2JwcZoVPjgdCQdnGUtwf66r" sg_b64 = "KuZVJ8kK6xCmujLfd8AjU3IfENn1WwcQRA0hI/WWzyXp97zerFg9XRx/ICHcHRGmvxstsul/QEDma2uHf6DIAEcr8Vs=" account_b64 = "TRza0pA9oaZw7tltPULKlkRaGV2qXT9vJx9q2HGY4Lom4qR3" msg = "aeternity".encode("utf-8") assert is_signature_valid(account_id, sg_ae, msg) assert is_signature_valid(hashing._base64_decode(account_b64), hashing._base64_decode(sg_b64), msg) msg = "wrong".encode("utf-8") assert not is_signature_valid(account_id, sg_ae, msg) assert not is_signature_valid(hashing._base64_decode(account_b64), hashing._base64_decode(sg_b64), msg)