summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-11 17:40:23 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-11 17:40:23 -0400
commite450d7a2d1bdde57d01f027b2e5b8080095f1380 (patch)
treed06f349e6f11bbf5b3e11db96b260fc032107b61 /keysafe.hs
parentdca9a15b797e30b095f306955310a40f2d1013b5 (diff)
downloadkeysafe-e450d7a2d1bdde57d01f027b2e5b8080095f1380.tar.gz
pluggable object storage layer
Diffstat (limited to 'keysafe.hs')
-rw-r--r--keysafe.hs29
1 files changed, 5 insertions, 24 deletions
diff --git a/keysafe.hs b/keysafe.hs
index 32361ab..962f10f 100644
--- a/keysafe.hs
+++ b/keysafe.hs
@@ -11,11 +11,8 @@ import Types
import Tunables
import Encryption
import Shard
-import Raaz.Core.Encode
-import System.IO
-import System.Posix.ByteString
-import qualified Data.ByteString as B
-import Control.DeepSeq
+import Storage
+import Storage.LocalFiles
main :: IO ()
main = do
@@ -28,7 +25,7 @@ storedemo = do
let esk = encrypt kek secretkey
let sis = shardIdents tunables name keyid
shards <- genShards esk tunables
- mapM_ (uncurry storeShard) (zip (getIdents sis) shards)
+ mapM_ (uncurry (storeShard localFiles)) (zip (getIdents sis) shards)
where
password = Password "foo"
name = Name "bar"
@@ -41,7 +38,8 @@ retrievedemo = do
let sis = shardIdents tunables name keyid
-- 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
+ shards <- map (\(RetrieveSuccess s) -> s)
+ <$> mapM (uncurry (retrieveShard localFiles)) l
let esk = combineShards tunables shards
kek <- genKeyEncryptionKey tunables name password
-- TODO: need to solve the encryption puzzle
@@ -53,20 +51,3 @@ retrievedemo = do
name = Name "bar"
tunables = testModeTunables -- defaultTunables
keyid = KeyId gpgKey "foobar"
-
-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 (toByteString s)
- hClose h
-
-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 (Shard n (StorableObject b))