summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
diff options
context:
space:
mode:
Diffstat (limited to 'keysafe.hs')
-rw-r--r--keysafe.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/keysafe.hs b/keysafe.hs
index 15deb79..f1d87fa 100644
--- a/keysafe.hs
+++ b/keysafe.hs
@@ -1,11 +1,20 @@
{-# LANGUAGE OverloadedStrings #-}
+{- Copyright 2016 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
module Main where
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
main :: IO ()
main = do
@@ -13,10 +22,19 @@ main = do
let esk = encrypt kek secretkey
let sis = shardIdents tunables name keyid
shards <- genShards esk tunables
- print $ zip (getIdents sis) shards
+ mapM_ (uncurry store) (zip (getIdents sis) shards)
where
password = Password "foo"
name = Name "bar"
tunables = testModeTunables -- defaultTunables
keyid = KeyId gpgKey "foobar"
secretkey = SecretKey "this is a gpg private key"
+
+store :: StorableObjectIdent -> StorableObject -> IO ()
+store i o = do
+ print $ toByteString i
+ fd <- openFd (toByteString i) WriteOnly (Just 0o666)
+ (defaultFileFlags { exclusive = True } )
+ h <- fdToHandle fd
+ B.hPut h (fromStorableObject o)
+ hClose h