From be4aea4b72b9544c4a982a883d7b66698d58272d Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Thu, 4 Jul 2019 06:59:57 -0400 Subject: Make ready for ascii-armor support. --- lib/KeyRing.hs | 6 ------ lib/KeyRing/BuildKeyDB.hs | 24 ++++++++++++------------ lib/KeyRing/Types.hs | 16 ++++++++++++---- 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 isMutable stream | KF_None <- fill stream = False isMutable _ = True -{- -pwfile :: FileType -> Maybe InputFile -pwfile (KeyRingFile f) = f -pwfile _ = Nothing --} - filesToLock :: 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 readp :: InputFile -> StreamInfo -> IO (StreamInfo, Message) readp f stream = fmap readp0 $ readPacketsFromFile ctx f where - readp0 ps = (stream { access = acc' }, ps) + readp0 (codec,ps) = (stream { access = acc', typ = PGPPackets codec }, ps) where acc' = case access stream of AutoAccess -> case ps of @@ -296,23 +296,23 @@ buildKeyDB ctx grip0 keyring = do isring :: FileType -> Bool -isring (KeyRingFile {}) = True -isring _ = False +isring (PGPPackets {}) = True +isring _ = False -readPacketsFromFile :: InputFileContext -> InputFile -> IO Message +readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) readPacketsFromFile ctx fname = do -- warn $ fname ++ ": reading..." input <- readInputFileL ctx fname + return $ (,) BinaryPackets $ #if MIN_VERSION_binary(0,7,0) - return $ Message $ flip fix input $ \again some -> - case decodeOrFail some of - Right (more,_,msg ) -> msg : again more - Left (_,_,_) -> - -- FIXME - -- trace (fname++": read fail") $ - [] + Message $ flip fix input $ \again some -> + case decodeOrFail some of + Right (more,_,msg ) -> msg : again more + Left (_,_,_) -> + -- TODO: try ascii armor + [] #else - return $ decode input + decode input #endif 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 @@ -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE PatternSynonyms #-} module KeyRing.Types where import Data.Char (isLower,toLower) @@ -179,13 +180,20 @@ data Access = AutoAccess -- ^ secret or public as appropriate based on existing | Pub -- ^ public information deriving (Eq,Ord,Show) -data FileType = KeyRingFile + +data PacketsCodec = DetectAscii | BinaryPackets | AsciiArmor + deriving (Eq,Ord,Show) + +data FileType = PGPPackets PacketsCodec | PEMFile | WalletFile | DNSPresentation | Hosts | SshFile - deriving (Eq,Ord,Enum,Show) + deriving (Eq,Ord,Show) + +pattern KeyRingFile :: FileType +pattern KeyRingFile = PGPPackets DetectAscii -- type UsageTag = String data Initializer = NoCreate | Internal GenerateKeyParams | External String | WarnMissing String -- cgit v1.2.3