-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the infrastructure for the first backend
- Loading branch information
Showing
5 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .main import Keccak256 # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .backends import ( | ||
pycryptodome, | ||
) | ||
from .main import ( | ||
Keccak256, | ||
) | ||
|
||
keccak = Keccak256(pycryptodome) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def keccak256(prehash): | ||
return b'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Keccak256: | ||
def __init__(self, backend): | ||
self.hasher = backend.keccak256 | ||
# TODO run assertion to validate hash once on load, after first backend set up | ||
|
||
def __call__(self, preimage): | ||
if not isinstance(preimage, bytes): | ||
raise TypeError("Can only compute the hash of a `bytes` value, not %r" % preimage) | ||
|
||
return self.hasher(preimage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def keccak(): | ||
from eth_hash.auto import keccak | ||
return keccak | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'prehash, expected_result', | ||
( | ||
( | ||
b'', | ||
b"\xc5\xd2F\x01\x86\xf7#<\x92~}\xb2\xdc\xc7\x03\xc0\xe5\x00\xb6S\xca\x82';{\xfa\xd8\x04]\x85\xa4p", # noqa: E501 | ||
), | ||
), | ||
) | ||
def test_keccak_256(keccak, prehash, expected_result): | ||
assert keccak(prehash) == expected_result |