From 3be996eb6450d0a183a93a37cc0cc091c8d2f921 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Wed, 11 May 2022 02:01:57 +0300 Subject: [PATCH] Replace obsolete pycrypto with pycryptodome to support jammy: pycrypto fails to install, openssl 3 has no ripemd160 hash. Also skip test_crypto.TestHashlib if openssl 3 is found. --- requirements.txt | 2 +- src/fallback/__init__.py | 4 ++-- src/tests/test_crypto.py | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index c7c599d5..ecb021cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ coverage psutil -pycrypto +pycryptodome PyQt5;python_version>="3.7" python_prctl;platform_system=="Linux" six diff --git a/src/fallback/__init__.py b/src/fallback/__init__.py index 9a8d646f..f65999a1 100644 --- a/src/fallback/__init__.py +++ b/src/fallback/__init__.py @@ -18,11 +18,11 @@ try: hashlib.new('ripemd160') except ValueError: try: - from Crypto.Hash import RIPEMD + from Crypto.Hash import RIPEMD160 except ImportError: RIPEMD160Hash = None else: - RIPEMD160Hash = RIPEMD.RIPEMD160Hash + RIPEMD160Hash = RIPEMD160.new else: def RIPEMD160Hash(data=None): """hashlib based RIPEMD160Hash""" diff --git a/src/tests/test_crypto.py b/src/tests/test_crypto.py index 38410359..e68e7ee5 100644 --- a/src/tests/test_crypto.py +++ b/src/tests/test_crypto.py @@ -3,6 +3,7 @@ Test the alternatives for crypto primitives """ import hashlib +import ssl import unittest from abc import ABCMeta, abstractmethod from binascii import hexlify @@ -11,9 +12,9 @@ from pybitmessage import highlevelcrypto try: - from Crypto.Hash import RIPEMD + from Crypto.Hash import RIPEMD160 except ImportError: - RIPEMD = None + RIPEMD160 = None from .samples import ( sample_pubsigningkey, sample_pubencryptionkey, @@ -42,6 +43,8 @@ class RIPEMD160TestCase(object): self.assertEqual(hexlify(self._hashdigest(pubkey_sha)), sample_ripe) +@unittest.skipIf( + ssl.OPENSSL_VERSION.startswith('OpenSSL 3'), 'no ripemd160 in openssl 3') class TestHashlib(RIPEMD160TestCase, unittest.TestCase): """RIPEMD160 test case for hashlib""" @staticmethod @@ -51,12 +54,12 @@ class TestHashlib(RIPEMD160TestCase, unittest.TestCase): return hasher.digest() -@unittest.skipUnless(RIPEMD, 'pycrypto package not found') +@unittest.skipUnless(RIPEMD160, 'pycrypto package not found') class TestCrypto(RIPEMD160TestCase, unittest.TestCase): """RIPEMD160 test case for Crypto""" @staticmethod def _hashdigest(data): - return RIPEMD.RIPEMD160Hash(data).digest() + return RIPEMD160.new(data).digest() class TestHighlevelcrypto(unittest.TestCase):