1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
Description: Use new cryptodome path
Use the cryptodome Debian namespace.
Author: Manuel Guerra <ar.manuelguerra@gmail.com>
Forwarded: https://github.com/ethereum/eth-hash/pull/65
Last-Update: 2025-07-04
--- a/eth_hash/backends/pycryptodome.py
+++ b/eth_hash/backends/pycryptodome.py
@@ -3,9 +3,19 @@ from typing import (
cast,
)
-from Crypto.Hash import (
- keccak,
-)
+try:
+ from Cryptodome.Hash import (
+ keccak,
+ )
+except ImportError:
+ try:
+ from Crypto.Hash import (
+ keccak,
+ )
+ except ImportError as exc:
+ raise ImportError(
+ "Could not import either 'Cryptodome' or 'Crypto' namespace. "
+ "Please install pycryptodome package.") from exc
from eth_hash.abc import (
BackendAPI,
--- a/tests/core/test_import_and_version.py
+++ b/tests/core/test_import_and_version.py
@@ -25,7 +25,15 @@ def test_import_auto_empty_crash(monkeyp
keccak,
)
- with mock.patch.dict("sys.modules", {"sha3": None, "Crypto.Hash": None}):
+ clean_module("eth_hash.backends.pycryptodome")
+ clean_module("eth_hash.backends.pysha3")
+
+ with mock.patch.dict("sys.modules", {
+ "sha3": None,
+ "Crypto": None,
+ "Cryptodome": None,
+ "eth_hash.backends": mock.MagicMock()
+ }):
with pytest.raises(
ImportError, match="None of these hashing backends are installed"
):
@@ -53,7 +61,15 @@ def test_load_by_env(monkeypatch, backen
)
monkeypatch.setenv("ETH_HASH_BACKEND", backend)
- with mock.patch.dict("sys.modules", {"sha3": None, "Crypto.Hash": None}):
+ clean_module("eth_hash.backends.pycryptodome")
+ clean_module("eth_hash.backends.pysha3")
+
+ with mock.patch.dict("sys.modules", {
+ "sha3": None,
+ "Crypto": None,
+ "Cryptodome": None,
+ "eth_hash.backends": mock.MagicMock()
+ }):
with pytest.raises(ImportError) as excinfo:
keccak(b"triggered")
expected_msg = (
|