Ecies encrypted string length can be different in rare cases

This commit is contained in:
shortcutme 2019-03-23 03:38:30 +01:00
parent e24d1016a5
commit 5c1ec0b141
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -11,12 +11,12 @@ class TestCrypt:
ecies_encrypted_text = "R5J1RFIDOzE5bnWopvccmALKACCk/CRcd/KSE9OgExJKASyMbZ57JVSUenL2TpABMmcT+wAgr2UrOqClxpOWvIUwvwwupXnMbRTzthhIJJrTRW3sCJVaYlGEMn9DAcvbflgEkQX/MVVdLV3tWKySs1Vk8sJC/y+4pGYCrZz7vwDNEEERaqU="
@pytest.mark.parametrize("text", [b"hello", '\xc1rv\xedzt\xfbr\xf5t\xfck\xf6rf\xfar\xf3g\xe9'.encode("utf8")])
@pytest.mark.parametrize("text_repeat", [1,10,1024])
@pytest.mark.parametrize("text_repeat", [1, 10, 128, 1024])
def testEncryptEcies(self, text, text_repeat):
text = text * text_repeat
aes_key, encrypted = CryptMessage.eciesEncrypt(text, self.publickey)
assert len(aes_key) == 32
assert len(encrypted) == 134 + int(len(text) / 16) * 16
# assert len(encrypted) == 134 + int(len(text) / 16) * 16 # Not always true
ecc = CryptMessage.getEcc(self.privatekey)
assert ecc.decrypt(encrypted) == text