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.
This commit is contained in:
Lee Miller 2022-05-11 02:01:57 +03:00
parent 8e708c6277
commit 3be996eb64
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
3 changed files with 10 additions and 7 deletions

View File

@ -1,6 +1,6 @@
coverage
psutil
pycrypto
pycryptodome
PyQt5;python_version>="3.7"
python_prctl;platform_system=="Linux"
six

View File

@ -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"""

View File

@ -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):