diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-11 17:06:47 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-11 17:06:47 -0400 |
commit | dca9a15b797e30b095f306955310a40f2d1013b5 (patch) | |
tree | ad555b482bb22e4da74ad5f50c286d8a8c96612c /keysafe.hs | |
parent | 34c15caaaa96689dd342999f7d9a098903fd25b9 (diff) | |
download | keysafe-dca9a15b797e30b095f306955310a40f2d1013b5.tar.gz |
Shard data type
Diffstat (limited to 'keysafe.hs')
-rw-r--r-- | keysafe.hs | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -39,9 +39,9 @@ storedemo = do retrievedemo :: IO () retrievedemo = do let sis = shardIdents tunables name keyid - shards <- mapM retrieveShard (drop 1 $ getIdents sis) - -- TODO: need to try all orders of shards until one works, - -- because the shard numbers are not preserved + -- we drop 1 to simulate not getting all shards from the servers + let l = drop 1 $ zip [1..] (getIdents sis) + shards <- mapM (uncurry retrieveShard) l let esk = combineShards tunables shards kek <- genKeyEncryptionKey tunables name password -- TODO: need to solve the encryption puzzle @@ -54,19 +54,19 @@ retrievedemo = do tunables = testModeTunables -- defaultTunables keyid = KeyId gpgKey "foobar" -storeShard :: StorableObjectIdent -> StorableObject -> IO () -storeShard i o = do +storeShard :: StorableObjectIdent -> Shard -> IO () +storeShard i s = do print $ toByteString i fd <- openFd (toByteString i) WriteOnly (Just 0o666) (defaultFileFlags { exclusive = True } ) h <- fdToHandle fd - B.hPut h (fromStorableObject o) + B.hPut h (toByteString s) hClose h -retrieveShard :: StorableObjectIdent -> IO StorableObject -retrieveShard i = do +retrieveShard :: Int -> StorableObjectIdent -> IO Shard +retrieveShard n i = do fd <- openFd (toByteString i) ReadOnly Nothing defaultFileFlags h <- fdToHandle fd b <- B.hGetContents h b `deepseq` hClose h - return (StorableObject b) + return (Shard n (StorableObject b)) |