Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace xxhash with xxhash-ffi #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion avl-auth.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ test-suite test
, base >=4.7 && <5
, cryptonite
, bytestring
, hashable
, memory
, binary
, containers
Expand All @@ -67,7 +68,7 @@ test-suite test
, QuickCheck
, HUnit
, quickcheck-instances
, xxhash
, xxhash-ffi
default-language: Haskell2010
default-extensions:
DeriveFoldable
Expand Down
9 changes: 5 additions & 4 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.ByteArray (ByteArrayAccess(..), convert)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Either (isLeft, isRight)
import Data.Hashable (hash)
import Data.Kind
import Data.List (sort)
import Data.List.NonEmpty (NonEmpty, toList)
Expand All @@ -30,22 +31,22 @@ import qualified Crypto.Data.Auth.Tree.Cryptonite as Cryptonite
import qualified Crypto.Data.Auth.Tree.Proof as Tree
import qualified Crypto.Hash as Cryptonite

import qualified Data.Digest.XXHash as Mock
import qualified Data.Digest.XXHash.FFI as Mock

type Key = Word8
type Val = Word8

type CryptoniteDigest = Cryptonite.Digest Cryptonite.SHA256
type MockDigest = Mock.XXHash
type MockDigest = Word64

instance MerkleHash (Cryptonite.Digest Cryptonite.SHA256) where
emptyHash = Cryptonite.emptyHash
hashLeaf = Cryptonite.hashLeaf
concatHashes = Cryptonite.concatHashes

instance MerkleHash MockDigest where
emptyHash = minBound
hashLeaf k v = Mock.xxHash' (convert k <> convert v)
emptyHash = 0
hashLeaf k v = fromIntegral $ hash $ Mock.XXH3 @ByteString (convert k <> convert v)
concatHashes d1 d2 = d1 + d2

instance MonadFail Gen where
Expand Down