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

make LargeKey serializable #4

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
2 changes: 1 addition & 1 deletion Crypto.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Library
Data.HMAC
Build-Depends: QuickCheck >= 2.4.0.1, HUnit
if flag(small_base)
Build-Depends: base >= 3, base < 5, array, random, pretty
Build-Depends: base >= 3, base < 5, array, random, pretty, data-serializer
else
Build-Depends: base < 3
Ghc-options: -fregs-graph
Expand Down
10 changes: 10 additions & 0 deletions Data/LargeWord.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE ScopedTypeVariables #-}

-----------------------------------------------------------------------------
-- |
-- Module : Data.LargeWord
Expand All @@ -20,6 +22,8 @@ import Data.Word
import Data.Bits
import Numeric
import Data.Char
import Data.Proxy(Proxy(Proxy))
import Data.Serializer(Serializable(put), SizedSerializable(size))

-- Keys have certain capabilities.

Expand Down Expand Up @@ -145,3 +149,9 @@ type Word160 = LargeKey Word32 Word128
type Word192 = LargeKey Word64 Word128
type Word224 = LargeKey Word32 Word192
type Word256 = LargeKey Word64 Word192

instance (Serializable a, Serializable b) => Serializable (LargeKey a b) where
put (LargeKey a b) = put a <> put b

instance (SizedSerializable a, SizedSerializable b) => SizedSerializable (LargeKey a b) where
size Proxy = size (Proxy :: Proxy a) + size (Proxy :: Proxy b)