diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-04 06:59:57 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-04 07:06:52 -0400 |
commit | be4aea4b72b9544c4a982a883d7b66698d58272d (patch) | |
tree | 4a71fc0f1fde35fc290ba22ecbf441ba8b0ec801 /lib/KeyRing | |
parent | 90d53ed9167c1263909d4488d940d585339d353c (diff) |
Make ready for ascii-armor support.
Diffstat (limited to 'lib/KeyRing')
-rw-r--r-- | lib/KeyRing/BuildKeyDB.hs | 24 | ||||
-rw-r--r-- | lib/KeyRing/Types.hs | 16 |
2 files changed, 24 insertions, 16 deletions
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 | ||
298 | isring :: FileType -> Bool | 298 | isring :: FileType -> Bool |
299 | isring (KeyRingFile {}) = True | 299 | isring (PGPPackets {}) = True |
300 | isring _ = False | 300 | isring _ = False |
301 | 301 | ||
302 | readPacketsFromFile :: InputFileContext -> InputFile -> IO Message | 302 | readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) |
303 | readPacketsFromFile ctx fname = do | 303 | readPacketsFromFile 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 | ||
318 | readPacketsFromWallet :: | 318 | readPacketsFromWallet :: |
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 #-} | ||
3 | module KeyRing.Types where | 4 | module KeyRing.Types where |
4 | 5 | ||
5 | import Data.Char (isLower,toLower) | 6 | import 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 | ||
182 | data FileType = KeyRingFile | 183 | |
184 | data PacketsCodec = DetectAscii | BinaryPackets | AsciiArmor | ||
185 | deriving (Eq,Ord,Show) | ||
186 | |||
187 | data 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 | |||
195 | pattern KeyRingFile :: FileType | ||
196 | pattern KeyRingFile = PGPPackets DetectAscii | ||
189 | 197 | ||
190 | -- type UsageTag = String | 198 | -- type UsageTag = String |
191 | data Initializer = NoCreate | Internal GenerateKeyParams | External String | WarnMissing String | 199 | data Initializer = NoCreate | Internal GenerateKeyParams | External String | WarnMissing String |