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:
parent
8e708c6277
commit
3be996eb64
|
@ -1,6 +1,6 @@
|
||||||
coverage
|
coverage
|
||||||
psutil
|
psutil
|
||||||
pycrypto
|
pycryptodome
|
||||||
PyQt5;python_version>="3.7"
|
PyQt5;python_version>="3.7"
|
||||||
python_prctl;platform_system=="Linux"
|
python_prctl;platform_system=="Linux"
|
||||||
six
|
six
|
||||||
|
|
|
@ -18,11 +18,11 @@ try:
|
||||||
hashlib.new('ripemd160')
|
hashlib.new('ripemd160')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
try:
|
||||||
from Crypto.Hash import RIPEMD
|
from Crypto.Hash import RIPEMD160
|
||||||
except ImportError:
|
except ImportError:
|
||||||
RIPEMD160Hash = None
|
RIPEMD160Hash = None
|
||||||
else:
|
else:
|
||||||
RIPEMD160Hash = RIPEMD.RIPEMD160Hash
|
RIPEMD160Hash = RIPEMD160.new
|
||||||
else:
|
else:
|
||||||
def RIPEMD160Hash(data=None):
|
def RIPEMD160Hash(data=None):
|
||||||
"""hashlib based RIPEMD160Hash"""
|
"""hashlib based RIPEMD160Hash"""
|
||||||
|
|
|
@ -3,6 +3,7 @@ Test the alternatives for crypto primitives
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import ssl
|
||||||
import unittest
|
import unittest
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
@ -11,9 +12,9 @@ from pybitmessage import highlevelcrypto
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from Crypto.Hash import RIPEMD
|
from Crypto.Hash import RIPEMD160
|
||||||
except ImportError:
|
except ImportError:
|
||||||
RIPEMD = None
|
RIPEMD160 = None
|
||||||
|
|
||||||
from .samples import (
|
from .samples import (
|
||||||
sample_pubsigningkey, sample_pubencryptionkey,
|
sample_pubsigningkey, sample_pubencryptionkey,
|
||||||
|
@ -42,6 +43,8 @@ class RIPEMD160TestCase(object):
|
||||||
self.assertEqual(hexlify(self._hashdigest(pubkey_sha)), sample_ripe)
|
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):
|
class TestHashlib(RIPEMD160TestCase, unittest.TestCase):
|
||||||
"""RIPEMD160 test case for hashlib"""
|
"""RIPEMD160 test case for hashlib"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -51,12 +54,12 @@ class TestHashlib(RIPEMD160TestCase, unittest.TestCase):
|
||||||
return hasher.digest()
|
return hasher.digest()
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(RIPEMD, 'pycrypto package not found')
|
@unittest.skipUnless(RIPEMD160, 'pycrypto package not found')
|
||||||
class TestCrypto(RIPEMD160TestCase, unittest.TestCase):
|
class TestCrypto(RIPEMD160TestCase, unittest.TestCase):
|
||||||
"""RIPEMD160 test case for Crypto"""
|
"""RIPEMD160 test case for Crypto"""
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _hashdigest(data):
|
def _hashdigest(data):
|
||||||
return RIPEMD.RIPEMD160Hash(data).digest()
|
return RIPEMD160.new(data).digest()
|
||||||
|
|
||||||
|
|
||||||
class TestHighlevelcrypto(unittest.TestCase):
|
class TestHighlevelcrypto(unittest.TestCase):
|
||||||
|
|
Reference in New Issue
Block a user