summaryrefslogtreecommitdiff
path: root/lib/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Types.hs')
-rw-r--r--lib/Types.hs38
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/Types.hs b/lib/Types.hs
index 686614e..dd519de 100644
--- a/lib/Types.hs
+++ b/lib/Types.hs
@@ -1,6 +1,8 @@
1{-# LANGUAGE DeriveFunctor #-} 1{-# LANGUAGE DeriveFunctor #-}
2module Types where 2module Types where
3 3
4import Data.Char (isLower,toLower)
5import Data.List (groupBy)
4import Data.Map as Map (Map) 6import Data.Map as Map (Map)
5import qualified Data.Map as Map 7import qualified Data.Map as Map
6import Data.OpenPGP 8import Data.OpenPGP
@@ -113,7 +115,7 @@ data PassphraseSpec = PassphraseSpec
113 -- ^ The passphrase will be read from this file or file descriptor. 115 -- ^ The passphrase will be read from this file or file descriptor.
114 } 116 }
115 -- | Use this to carry pasphrases from a previous run. 117 -- | Use this to carry pasphrases from a previous run.
116 | PassphraseMemoizer PacketTranscoder 118 | PassphraseMemoizer { passSpecTranscoder :: PacketTranscoder }
117 | PassphraseAgent 119 | PassphraseAgent
118 120
119instance Show PassphraseSpec where 121instance Show PassphraseSpec where
@@ -125,7 +127,24 @@ instance Eq PassphraseSpec where
125 _ == _ 127 _ == _
126 = False 128 = False
127 129
128 130-- Ord instance for PassphraseSpec generally orders by generality with the most
131-- general being greatest and the least general being least. The one exception
132-- is the 'PassphraseMemoizer' which is considered least of all even though it
133-- is very general. This is so an existing memoizer will be tried first, and
134-- if there is none, one will be created that tries the others in order of
135-- increasing generality. Key-specialization is considered less general than
136-- file-specialization.
137instance Ord PassphraseSpec where
138 compare (PassphraseMemoizer _) (PassphraseMemoizer _) = EQ
139 compare PassphraseAgent PassphraseAgent = EQ
140 compare (PassphraseMemoizer _) _ = LT
141 compare (PassphraseSpec a b c) (PassphraseSpec d e f)
142 | fmap (const ()) a == fmap (const ()) d
143 && fmap (const ()) b == fmap (const ()) e = compare (a,b,c) (d,e,f)
144 compare (PassphraseSpec (Just _) (Just _) _) _ = LT
145 compare (PassphraseSpec Nothing (Just _) _) _ = LT
146 compare (PassphraseSpec (Just _) _ _) _ = LT
147 compare PassphraseAgent _ = GT
129 148
130data Transform = 149data Transform =
131 Autosign 150 Autosign
@@ -253,6 +272,21 @@ instance Applicative KikiCondition where
253 Left err -> err 272 Left err -> err
254 Left err -> err 273 Left err -> err
255 274
275uncamel :: String -> String
276uncamel str = unwords $ firstWord ++ (toLower .: otherWords) ++ args
277 where
278 (.:) = fmap . fmap
279 ( firstWord ,
280 otherWords ) = splitAt 1 ws
281 ws = camel >>= groupBy (\_ c -> isLower c)
282 ( camel, args) = splitAt 1 $ words str
283
284errorString :: KikiCondition a -> String
285errorString (KikiSuccess {}) = "success"
286errorString e = uncamel . show $ fmap (const ()) e
287
288
289
256data InputFileContext = InputFileContext 290data InputFileContext = InputFileContext
257 { homesecPath :: FilePath 291 { homesecPath :: FilePath
258 , homepubPath :: FilePath 292 , homepubPath :: FilePath