diff options
Diffstat (limited to 'lib/KeyRing/BuildKeyDB.hs')
-rw-r--r-- | lib/KeyRing/BuildKeyDB.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/KeyRing/BuildKeyDB.hs b/lib/KeyRing/BuildKeyDB.hs index 10e2d41..24b39b1 100644 --- a/lib/KeyRing/BuildKeyDB.hs +++ b/lib/KeyRing/BuildKeyDB.hs | |||
@@ -32,7 +32,7 @@ import Data.ASN1.Types (ASN1 (BitString, End, IntVal, Null, OID, Start | |||
32 | fromASN1, toASN1) | 32 | fromASN1, toASN1) |
33 | import Data.Binary | 33 | import Data.Binary |
34 | import Data.Bits ((.&.), (.|.)) | 34 | import Data.Bits ((.&.), (.|.)) |
35 | import Data.Bits (Bits) | 35 | import Data.Bits (Bits, testBit) |
36 | import qualified Data.ByteString as S (ByteString, breakSubstring, | 36 | import qualified Data.ByteString as S (ByteString, breakSubstring, |
37 | concat, drop, hGetContents, | 37 | concat, drop, hGetContents, |
38 | hPutStr, length, null, | 38 | hPutStr, length, null, |
@@ -41,7 +41,7 @@ import Data.ByteString.Lazy (ByteString) | |||
41 | import qualified Data.ByteString.Lazy as L (ByteString, concat, empty, | 41 | import qualified Data.ByteString.Lazy as L (ByteString, concat, empty, |
42 | fromChunks, hGetContents, | 42 | fromChunks, hGetContents, |
43 | null, readFile, toChunks, | 43 | null, readFile, toChunks, |
44 | toStrict) | 44 | toStrict, head) |
45 | import Data.Char | 45 | import Data.Char |
46 | import Data.Function | 46 | import Data.Function |
47 | import Data.List | 47 | import Data.List |
@@ -318,13 +318,16 @@ decodeOrFail bs = Right (L.empty,1,decode bs) | |||
318 | 318 | ||
319 | readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) | 319 | readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) |
320 | readPacketsFromFile ctx fname = do | 320 | readPacketsFromFile ctx fname = do |
321 | -- warn $ fname ++ ": reading..." | ||
322 | input <- readInputFileL ctx fname | 321 | input <- readInputFileL ctx fname |
323 | return $ case decodeOrFail input of | 322 | let tryBinary = case decodeOrFail input of |
324 | Right (more,_,pkt) -> (,) BinaryPackets $ Message $ pkt : decodePacketList more | 323 | Right (more,_,pkt) -> (,) BinaryPackets $ Message $ pkt : decodePacketList more |
325 | Left (_,_,_) -> case ASCIIArmor.decodeLazy input of | 324 | Left (_,_,_) -> tryAscii |
325 | tryAscii = case ASCIIArmor.decodeLazy input of | ||
326 | Right (Armor pubOrSec headers bs:_) -> (,) AsciiArmor $ Message $ decodePacketList bs | 326 | Right (Armor pubOrSec headers bs:_) -> (,) AsciiArmor $ Message $ decodePacketList bs |
327 | _ -> (,) DetectAscii $ Message [] | 327 | _ -> (,) DetectAscii $ Message [] |
328 | return $ if L.null input || testBit (L.head input) 7 | ||
329 | then tryBinary | ||
330 | else tryAscii | ||
328 | 331 | ||
329 | readPacketsFromWallet :: | 332 | readPacketsFromWallet :: |
330 | Maybe Packet | 333 | Maybe Packet |