summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-11 16:33:26 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-11 16:33:26 -0400
commitb2719f6e84c0c1f49ac6ab9b60846a899563961c (patch)
tree47c93357b3362e71baf0bf83a21372ae376dfba5 /keysafe.hs
parent5decbad3eb779b1bbe11245cbde84701909e9c68 (diff)
downloadkeysafe-b2719f6e84c0c1f49ac6ab9b60846a899563961c.tar.gz
inline slightly modified version of secret-sharing
Needed for efficient serialization of shares, unless upstream takes my suggestion to make the finite field be size 256.
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