diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-14 09:38:04 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-14 09:38:04 -0400 |
commit | 2a271b27c65a286882332b6268e8946851c52f2a (patch) | |
tree | b46233a6285834d89947193a36df72341519b818 /Hash.hs | |
parent | de7af3470e0b972ea9498f7ed07e6b38e8f15d03 (diff) | |
download | debug-me-2a271b27c65a286882332b6268e8946851c52f2a.tar.gz |
add JSON serialization
Fairly straightforward, but did have to decide how to encode all the
ByteStrings, since they are not necessarily utf-8. Used base64.
This commit was sponsored by Henrik Riomar on Patreon.
Diffstat (limited to 'Hash.hs')
-rw-r--r-- | Hash.hs | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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] |