summaryrefslogtreecommitdiffhomepage
path: root/Hash.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Hash.hs')
-rw-r--r--Hash.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/Hash.hs b/Hash.hs
index eca00e4..4174d5f 100644
--- a/Hash.hs
+++ b/Hash.hs
@@ -8,19 +8,22 @@ import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C8
import qualified Crypto.Hash as H
--- | Encode a hash pointer using base16 format.
-encodeHashPointer :: HashPointer -> B.ByteString
-encodeHashPointer (HashPointer d) = C8.pack (show d)
-
class Hashable a where
hash :: a -> HashPointer
instance Hashable B.ByteString where
- hash = HashPointer . H.hash
+ -- 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, encoding them in base16 format.
+-- | Hash the concacenation of the hashes.
instance Hashable [HashPointer] where
- hash = hash . B.concat . map encodeHashPointer
+ hash = hash . B.concat . map (val . hashValue)
instance Hashable a => Hashable (Activity a) where
hash (Activity a p s) = hash [hash a, p, hash s]