summaryrefslogtreecommitdiff
path: root/lib/KeyRing/BuildKeyDB.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/KeyRing/BuildKeyDB.hs')
-rw-r--r--lib/KeyRing/BuildKeyDB.hs31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/KeyRing/BuildKeyDB.hs b/lib/KeyRing/BuildKeyDB.hs
index f5b09ca..234d2ef 100644
--- a/lib/KeyRing/BuildKeyDB.hs
+++ b/lib/KeyRing/BuildKeyDB.hs
@@ -17,6 +17,8 @@ import qualified Data.ByteString as S
17import qualified Codec.Binary.Base32 as Base32 17import qualified Codec.Binary.Base32 as Base32
18import qualified Codec.Binary.Base64 as Base64 18import qualified Codec.Binary.Base64 as Base64
19#endif 19#endif
20import qualified Codec.Encryption.OpenPGP.ASCIIArmor as ASCIIArmor
21import Codec.Encryption.OpenPGP.ASCIIArmor.Types
20import Control.Applicative (liftA2) 22import Control.Applicative (liftA2)
21import Control.Arrow (first, second) 23import Control.Arrow (first, second)
22import Control.Exception (catch) 24import Control.Exception (catch)
@@ -299,22 +301,29 @@ isring :: FileType -> Bool
299isring (PGPPackets {}) = True 301isring (PGPPackets {}) = True
300isring _ = False 302isring _ = False
301 303
302readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) 304decodePacketList :: L.ByteString -> [Packet]
303readPacketsFromFile ctx fname = do 305decodePacketList some =
304 -- warn $ fname ++ ": reading..."
305 input <- readInputFileL ctx fname
306 return $ (,) BinaryPackets $
307#if MIN_VERSION_binary(0,7,0) 306#if MIN_VERSION_binary(0,7,0)
308 Message $ flip fix input $ \again some ->
309 case decodeOrFail some of 307 case decodeOrFail some of
310 Right (more,_,msg ) -> msg : again more 308 Right (more,_,msg ) -> msg : decodePacketList more
311 Left (_,_,_) -> 309 Left (_,_,_) -> []
312 -- TODO: try ascii armor
313 []
314#else 310#else
315 decode input 311 either (const []) (\(Message xs) -> xs) $ decode input
312
313decodeOrFail bs = Right (L.empty,1,decode bs)
316#endif 314#endif
317 315
316
317readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message)
318readPacketsFromFile ctx fname = do
319 -- warn $ fname ++ ": reading..."
320 input <- readInputFileL ctx fname
321 return $ case decodeOrFail input of
322 Right (more,_,pkt) -> (,) BinaryPackets $ Message $ pkt : decodePacketList more
323 Left (_,_,_) -> case ASCIIArmor.decodeLazy input of
324 Right (Armor pubOrSec headers bs:_) -> (,) AsciiArmor $ Message $ decodePacketList bs
325 Left errmsg -> (,) DetectAscii $ Message []
326
318readPacketsFromWallet :: 327readPacketsFromWallet ::
319 Maybe Packet 328 Maybe Packet
320 -> InputFile 329 -> InputFile