From 1c7e875f67e31c68e76c660294b67078acd4f38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Mon, 6 May 2019 21:50:47 +0200 Subject: Multiple signatures in Signed object --- src/PubKey.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/PubKey.hs') diff --git a/src/PubKey.hs b/src/PubKey.hs index d89747a..af4d03b 100644 --- a/src/PubKey.hs +++ b/src/PubKey.hs @@ -2,7 +2,7 @@ module PubKey ( PublicKey, SecretKey, Signature(sigKey), Signed(..), generateKeys, - sign, + sign, signAdd, ) where import Control.Monad @@ -29,7 +29,7 @@ data Signature = Signature data Signed a = Signed { signedData :: Stored a - , signedSignature :: Stored Signature + , signedSignature :: [Stored Signature] } deriving (Show) @@ -59,11 +59,11 @@ instance Storable Signature where instance Storable a => Storable (Signed a) where store' sig = storeRec $ do storeRef "data" $ signedData sig - storeRef "sig" $ signedSignature sig + mapM_ (storeRef "sig") $ signedSignature sig load' = loadRec $ Signed <$> loadRef "data" - <*> loadRef "sig" + <*> loadRefs "sig" generateKeys :: Storage -> IO (SecretKey, Stored PublicKey) @@ -73,8 +73,11 @@ generateKeys st = do return (SecretKey secret public, public) sign :: SecretKey -> Stored a -> IO (Signed a) -sign (SecretKey secret spublic) val = do +sign secret val = signAdd secret $ Signed val [] + +signAdd :: SecretKey -> Signed a -> IO (Signed a) +signAdd (SecretKey secret spublic) (Signed val sigs) = do let PublicKey public = fromStored spublic sig = ED.sign secret public $ storedRef val ssig <- wrappedStore (storedStorage val) $ Signature spublic sig - return $ Signed val ssig + return $ Signed val (ssig : sigs) -- cgit v1.2.3