summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-07-04 06:59:57 -0400
committerJoe Crayne <joe@jerkface.net>2019-07-04 07:06:52 -0400
commitbe4aea4b72b9544c4a982a883d7b66698d58272d (patch)
tree4a71fc0f1fde35fc290ba22ecbf441ba8b0ec801 /lib
parent90d53ed9167c1263909d4488d940d585339d353c (diff)
Make ready for ascii-armor support.
Diffstat (limited to 'lib')
-rw-r--r--lib/KeyRing.hs6
-rw-r--r--lib/KeyRing/BuildKeyDB.hs24
-rw-r--r--lib/KeyRing/Types.hs16
3 files changed, 24 insertions, 22 deletions
diff --git a/lib/KeyRing.hs b/lib/KeyRing.hs
index d85d2eb..44c3dce 100644
--- a/lib/KeyRing.hs
+++ b/lib/KeyRing.hs
@@ -173,12 +173,6 @@ isMutable :: StreamInfo -> Bool
173isMutable stream | KF_None <- fill stream = False 173isMutable stream | KF_None <- fill stream = False
174isMutable _ = True 174isMutable _ = True
175 175
176{-
177pwfile :: FileType -> Maybe InputFile
178pwfile (KeyRingFile f) = f
179pwfile _ = Nothing
180-}
181
182 176
183filesToLock :: 177filesToLock ::
184 KeyRingOperation -> InputFileContext -> [FilePath] 178 KeyRingOperation -> InputFileContext -> [FilePath]
diff --git a/lib/KeyRing/BuildKeyDB.hs b/lib/KeyRing/BuildKeyDB.hs
index ba5bafe..f5b09ca 100644
--- a/lib/KeyRing/BuildKeyDB.hs
+++ b/lib/KeyRing/BuildKeyDB.hs
@@ -150,7 +150,7 @@ buildKeyDB ctx grip0 keyring = do
150 readp :: InputFile -> StreamInfo -> IO (StreamInfo, Message) 150 readp :: InputFile -> StreamInfo -> IO (StreamInfo, Message)
151 readp f stream = fmap readp0 $ readPacketsFromFile ctx f 151 readp f stream = fmap readp0 $ readPacketsFromFile ctx f
152 where 152 where
153 readp0 ps = (stream { access = acc' }, ps) 153 readp0 (codec,ps) = (stream { access = acc', typ = PGPPackets codec }, ps)
154 where acc' = case access stream of 154 where acc' = case access stream of
155 AutoAccess -> 155 AutoAccess ->
156 case ps of 156 case ps of
@@ -296,23 +296,23 @@ buildKeyDB ctx grip0 keyring = do
296 296
297 297
298isring :: FileType -> Bool 298isring :: FileType -> Bool
299isring (KeyRingFile {}) = True 299isring (PGPPackets {}) = True
300isring _ = False 300isring _ = False
301 301
302readPacketsFromFile :: InputFileContext -> InputFile -> IO Message 302readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message)
303readPacketsFromFile ctx fname = do 303readPacketsFromFile ctx fname = do
304 -- warn $ fname ++ ": reading..." 304 -- warn $ fname ++ ": reading..."
305 input <- readInputFileL ctx fname 305 input <- readInputFileL ctx fname
306 return $ (,) BinaryPackets $
306#if MIN_VERSION_binary(0,7,0) 307#if MIN_VERSION_binary(0,7,0)
307 return $ Message $ flip fix input $ \again some -> 308 Message $ flip fix input $ \again some ->
308 case decodeOrFail some of 309 case decodeOrFail some of
309 Right (more,_,msg ) -> msg : again more 310 Right (more,_,msg ) -> msg : again more
310 Left (_,_,_) -> 311 Left (_,_,_) ->
311 -- FIXME 312 -- TODO: try ascii armor
312 -- trace (fname++": read fail") $ 313 []
313 []
314#else 314#else
315 return $ decode input 315 decode input
316#endif 316#endif
317 317
318readPacketsFromWallet :: 318readPacketsFromWallet ::
diff --git a/lib/KeyRing/Types.hs b/lib/KeyRing/Types.hs
index 6b686d5..22937a7 100644
--- a/lib/KeyRing/Types.hs
+++ b/lib/KeyRing/Types.hs
@@ -1,5 +1,6 @@
1{-# LANGUAGE DeriveAnyClass #-} 1{-# LANGUAGE DeriveAnyClass #-}
2{-# LANGUAGE DeriveFunctor #-} 2{-# LANGUAGE DeriveFunctor #-}
3{-# LANGUAGE PatternSynonyms #-}
3module KeyRing.Types where 4module KeyRing.Types where
4 5
5import Data.Char (isLower,toLower) 6import Data.Char (isLower,toLower)
@@ -179,13 +180,20 @@ data Access = AutoAccess -- ^ secret or public as appropriate based on existing
179 | Pub -- ^ public information 180 | Pub -- ^ public information
180 deriving (Eq,Ord,Show) 181 deriving (Eq,Ord,Show)
181 182
182data FileType = KeyRingFile 183
184data PacketsCodec = DetectAscii | BinaryPackets | AsciiArmor
185 deriving (Eq,Ord,Show)
186
187data FileType = PGPPackets PacketsCodec
183 | PEMFile 188 | PEMFile
184 | WalletFile 189 | WalletFile
185 | DNSPresentation 190 | DNSPresentation
186 | Hosts 191 | Hosts
187 | SshFile 192 | SshFile
188 deriving (Eq,Ord,Enum,Show) 193 deriving (Eq,Ord,Show)
194
195pattern KeyRingFile :: FileType
196pattern KeyRingFile = PGPPackets DetectAscii
189 197
190-- type UsageTag = String 198-- type UsageTag = String
191data Initializer = NoCreate | Internal GenerateKeyParams | External String | WarnMissing String 199data Initializer = NoCreate | Internal GenerateKeyParams | External String | WarnMissing String