summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-14 19:12:37 -0400
committerjoe <joe@jerkface.net>2014-04-14 19:12:37 -0400
commit769ffa643557af7e2b10f7034a4690f4d0ebe6e4 (patch)
tree410e76eb65e9e92a0ba62383db6a31919e8775b7 /KeyRing.hs
parented9ecad17bf8d916eb8780b0e9a46597aeab7ae3 (diff)
runKeyRing method
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs60
1 files changed, 35 insertions, 25 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index c05e9e7..cdfcd34 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -36,9 +36,13 @@ home = HomeDir
36 36
37data InputFile = HomeSec | HomePub | ArgFile FilePath | FileDesc Int 37data InputFile = HomeSec | HomePub | ArgFile FilePath | FileDesc Int
38 38
39data FileType = KeyRingFile | PEMFile | WalletFile 39type UsageTag = String
40type Initializer = String
41type PassWordFile = InputFile
40 42
41data RefType = ConstRef | MutableRef 43data FileType = KeyRingFile PassWordFile | PEMFile UsageTag | WalletFile
44
45data RefType = ConstRef | MutableRef (Maybe Initializer)
42 46
43 47
44data KeyRingRuntime = KeyRingRuntime 48data KeyRingRuntime = KeyRingRuntime
@@ -53,9 +57,22 @@ data KeyRingAction a = KeyRingAction a | RunTimeAction (KeyRingRuntime -> a)
53 57
54data KeyRingData = KeyRingData 58data KeyRingData = KeyRingData
55 { kFiles :: Map.Map InputFile (RefType,FileType) 59 { kFiles :: Map.Map InputFile (RefType,FileType)
60 , kImports :: Map.Map String (KeyData -> Bool)
56 , homeSpec :: Maybe String 61 , homeSpec :: Maybe String
57 } 62 }
58 63
64filesToLock k secring pubring = do
65 (f,(rtyp,ftyp)) <- Map.toList (kFiles k)
66 case rtyp of
67 ConstRef -> []
68 MutableRef {} -> resolve f
69 where
70 resolve HomeSec = return secring
71 resolve HomePub = return pubring
72 resolve (ArgFile f) = return f
73 resolve _ = []
74
75
59-- kret :: a -> KeyRingData a 76-- kret :: a -> KeyRingData a
60-- kret x = KeyRingData Map.empty Nothing (KeyRingAction x) 77-- kret x = KeyRingData Map.empty Nothing (KeyRingAction x)
61 78
@@ -85,21 +102,10 @@ data KikiResult a = KikiResult
85 , kikiReport :: [ (FilePath, KikiReportAction) ] 102 , kikiReport :: [ (FilePath, KikiReportAction) ]
86 } 103 }
87 104
88{- 105runKeyRing :: KeyRingData -> (KeyRingRuntime -> a) -> IO (KikiResult a)
89empty = KeyRingData { filesToLock = [] 106runKeyRing keyring op = do
90 , homeSpec = Nothing
91 , kaction = \KeyRingRuntime {} -> return ()
92 , keyringFiles = []
93 , walletFiles = []
94 }
95
96runKeyRing :: KeyRingData a -> IO (KikiResult a)
97runKeyRing keyring = do
98 (homedir,secring,pubring,grip0) <- getHomeDir (homeSpec keyring) 107 (homedir,secring,pubring,grip0) <- getHomeDir (homeSpec keyring)
99 let tolocks = map resolve (filesToLock keyring) 108 let tolocks = filesToLock keyring secring pubring
100 where resolve (ArgFile f) = f
101 resolve HomePub = pubring
102 resolve HomeSec = secring
103 lks <- forM tolocks $ \f -> do 109 lks <- forM tolocks $ \f -> do
104 lk <- dotlock_create f 0 110 lk <- dotlock_create f 0
105 v <- flip (maybe $ return Nothing) lk $ \lk -> do 111 v <- flip (maybe $ return Nothing) lk $ \lk -> do
@@ -109,23 +115,27 @@ runKeyRing keyring = do
109 return (v,f) 115 return (v,f)
110 let (lked, map snd -> failed) = partition (isJust . fst) lks 116 let (lked, map snd -> failed) = partition (isJust . fst) lks
111 ret = if null failed then KikiSuccess () else FailedToLock failed 117 ret = if null failed then KikiSuccess () else FailedToLock failed
112
113 ret <- case functorToEither ret of 118 ret <- case functorToEither ret of
114 Right {} -> do 119 Right {} -> do
115 a <- kaction keyring KeyRingRuntime 120 report <- todo -- build db
121
122 a <- return $ op KeyRingRuntime
116 { rtPubring = pubring 123 { rtPubring = pubring
117 , rtSecring = secring 124 , rtSecring = secring
118 , rtRings = secring:pubring:keyringFiles keyring 125 , rtRings = [] -- todo secring:pubring:keyringFiles keyring
119 , rtWallets = walletFiles keyring 126 , rtWallets = [] -- todo walletFiles keyring
120 , rtGrip = grip0 127 , rtGrip = grip0
121 } 128 }
122 return (KikiSuccess a) 129 report <- todo report -- write files
123 Left err -> return err 130
131 return $ KikiResult (KikiSuccess a) report
132 Left err -> return $ KikiResult err []
124 133
125 forM_ lked $ \(Just lk, fname) -> do dotlock_release lk 134 forM_ lked $ \(Just lk, fname) -> do dotlock_release lk
126 dotlock_destroy lk 135 dotlock_destroy lk -- todo: verify we want this
127 return KikiResult { kikiCondition = ret, kikiReport = [] } 136
128-} 137 return ret
138
129 139
130parseOptionFile fname = do 140parseOptionFile fname = do
131 xs <- fmap lines (readFile fname) 141 xs <- fmap lines (readFile fname)