summaryrefslogtreecommitdiffhomepage
path: root/Types.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-18 16:35:38 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-18 16:35:38 -0400
commitd73352f848b79224a94e531bb651897321064998 (patch)
tree4e4bb7f13113bfffc950a0451dd89b6ca8160070 /Types.hs
parenta70548f6dade6d93d482510a1b68b99327ec7f4a (diff)
downloaddebug-me-d73352f848b79224a94e531bb651897321064998.tar.gz
initial Crypto
Will use Ed25519 because it's from DJB and well regarded and in common use now.
Diffstat (limited to 'Types.hs')
-rw-r--r--Types.hs34
1 files changed, 18 insertions, 16 deletions
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
+