Skip to content

Commit

Permalink
add the infrastructure for the first backend
Browse files Browse the repository at this point in the history
  • Loading branch information
carver committed Feb 7, 2018
1 parent 8afe980 commit e673a1f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions eth_hash/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .main import Keccak256 # noqa: F401
4 changes: 4 additions & 0 deletions eth_hash/auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .main import Keccak256
from .backends import pycryptodome

keccak = Keccak256(pycryptodome)
2 changes: 2 additions & 0 deletions eth_hash/backends/pycryptodome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def keccak256(prehash):
return b''
10 changes: 10 additions & 0 deletions eth_hash/main.py
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)
20 changes: 20 additions & 0 deletions tests/core/test_results.py
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

0 comments on commit e673a1f

Please sign in to comment.