{-# LANGUAGE FlexibleInstances #-} module Hash where import Types import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as C8 import qualified Crypto.Hash as H class Hashable a where hash :: a -> HashPointer instance Hashable B.ByteString where -- Encodes the SHA256 using base16 format hash = HashPointer SHA256 . Val . C8.pack . show . sha256 instance Hashable Val where hash (Val v) = hash v sha256 :: B.ByteString -> H.Digest H.SHA256 sha256 = H.hash -- | Hash the concacenation of the hashes. instance Hashable [HashPointer] where hash = hash . B.concat . map (val . hashValue) instance Hashable a => Hashable (Activity a) where hash (Activity a (Just p) s) = hash [hash a, p, hash s] hash (Activity a Nothing s) = hash [hash a, hash s] instance Hashable Entered where hash v = hash [hash (enteredData v), hash (echoData v)] instance Hashable Seen where hash v = hash [hash (seenData v)] instance Hashable Signature where hash (Signature s) = hash s