diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-08-11 16:33:26 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-08-11 16:33:26 -0400 |
commit | b2719f6e84c0c1f49ac6ab9b60846a899563961c (patch) | |
tree | 47c93357b3362e71baf0bf83a21372ae376dfba5 /keysafe.hs | |
parent | 5decbad3eb779b1bbe11245cbde84701909e9c68 (diff) | |
download | keysafe-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.hs | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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 |