From d73352f848b79224a94e531bb651897321064998 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Apr 2017 16:35:38 -0400 Subject: initial Crypto Will use Ed25519 because it's from DJB and well regarded and in common use now. --- Types.hs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index ec21254..dbbb432 100644 --- a/Types.hs +++ b/Types.hs @@ -13,10 +13,7 @@ module Types ( import Val import Memory - -import GHC.Generics (Generic) -import Data.Aeson -import qualified Data.Aeson.Types as Aeson +import Json -- | Things that the developer sees. data Seen = Seen @@ -67,12 +64,6 @@ instance DataSize a => DataSize (Activity a) where + maybe 0 dataSize (prevActivity a) + dataSize (signature a) -newtype Signature = Signature Val - deriving (Show, Generic) - -instance DataSize Signature where - dataSize _ = 42 -- FIXME real size here - data Hash = Hash { hashMethod :: HashMethod , hashValue :: Val @@ -88,6 +79,16 @@ instance DataSize Hash where data HashMethod = SHA256 | SHA3 deriving (Show, Generic, Eq) +data Signature + = Ed25519 Val + | Unsigned + -- ^ Not used, but included to future-proof the JSON format. + deriving (Show, Generic) + +instance DataSize Signature where + dataSize (Ed25519 _) = 64 + dataSize Unsigned = 0 + instance ToJSON Seen instance FromJSON Seen instance ToJSON Entered @@ -96,17 +97,11 @@ instance ToJSON (Activity Seen) instance FromJSON (Activity Seen) instance ToJSON (Activity Entered) instance FromJSON (Activity Entered) -instance ToJSON Signature -instance FromJSON Signature instance ToJSON Hash instance FromJSON Hash instance ToJSON HashMethod instance FromJSON HashMethod --- | Nicer JSON encoding for sum types. -sumOptions :: Aeson.Options -sumOptions = defaultOptions { Aeson.sumEncoding = Aeson.ObjectWithSingleField } - instance ToJSON (Proto Seen) where toJSON = genericToJSON sumOptions toEncoding = genericToEncoding sumOptions @@ -118,3 +113,10 @@ instance ToJSON (Proto Entered) where toEncoding = genericToEncoding sumOptions instance FromJSON (Proto Entered) where parseJSON = genericParseJSON sumOptions + +instance ToJSON Signature where + toJSON = genericToJSON sumOptions + toEncoding = genericToEncoding sumOptions +instance FromJSON Signature where + parseJSON = genericParseJSON sumOptions + -- cgit v1.2.3