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

[inferno-vc] Made vcHash consistent between 32bit and 64bit architectures #150

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 8 additions & 19 deletions inferno-types/src/Inferno/Types/VersionControl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Crypto.Hash (Context, Digest, digestFromByteString, hashFinalize, hashIni
import Crypto.Hash.Algorithms (SHA256)
import Data.Aeson (FromJSON (..), FromJSONKey, ToJSON (..), ToJSONKey, withText)
import Data.ByteArray (ByteArrayAccess, convert)
import Data.ByteArray.Pack (fill, putStorable)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Base64.URL as Base64
import qualified Data.ByteString.Char8 as Char8
Expand Down Expand Up @@ -164,13 +163,13 @@ instance VCHashUpdate a => VCHashUpdate (NonEmpty.NonEmpty a) where
ctxt &< xs = ctxt &< NonEmpty.toList xs

instance VCHashUpdate a => VCHashUpdate (Set.Set a) where
ctxt &< xs = ctxt &< Set.toList xs
ctxt &< xs = ctxt &< Set.toAscList xs

instance (VCHashUpdate k, VCHashUpdate a) => VCHashUpdate (Map.Map k a) where
ctxt &< m = ctxt &< Map.toList m
ctxt &< m = ctxt &< Map.toAscList m

instance VCHashUpdate a => VCHashUpdate (IntMap.IntMap a) where
ctxt &< m = ctxt &< IntMap.toList m
ctxt &< m = ctxt &< IntMap.toAscList m

class GenericVCHashUpdate f where
genHashUpdate :: Context SHA256 -> f p -> Context SHA256
Expand Down Expand Up @@ -210,25 +209,15 @@ instance VCHashUpdate VCObjectHash where

deriving instance VCHashUpdate ImplExpl

instance VCHashUpdate Int64 where
(&<) =
hashUpdateVia (\i64 -> either error (id :: ByteString -> ByteString) $ fill (sizeOf i64) $ putStorable i64)
deriving via (VCHashUpdateViaShow Int64) instance VCHashUpdate Int64

instance VCHashUpdate Int32 where
(&<) =
hashUpdateVia (\i32 -> either error (id :: ByteString -> ByteString) $ fill (sizeOf i32) $ putStorable i32)
deriving via (VCHashUpdateViaShow Int32) instance VCHashUpdate Int32

instance VCHashUpdate Double where
(&<) =
hashUpdateVia (\d -> either error (id :: ByteString -> ByteString) $ fill (sizeOf d) $ putStorable d)
deriving via (VCHashUpdateViaShow Double) instance VCHashUpdate Double

instance VCHashUpdate Word32 where
(&<) =
hashUpdateVia (\w32 -> either error (id :: ByteString -> ByteString) $ fill (sizeOf w32) $ putStorable w32)
deriving via (VCHashUpdateViaShow Word64) instance VCHashUpdate Word64

instance VCHashUpdate Word64 where
(&<) =
hashUpdateVia (\w64 -> either error (id :: ByteString -> ByteString) $ fill (sizeOf w64) $ putStorable w64)
deriving via (VCHashUpdateViaShow Word32) instance VCHashUpdate Word32

deriving instance VCHashUpdate Lit

Expand Down
Loading