diff options
Diffstat (limited to 'lib/KeyRing')
-rw-r--r-- | lib/KeyRing/BuildKeyDB.hs | 31 |
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 | |||
17 | import qualified Codec.Binary.Base32 as Base32 | 17 | import qualified Codec.Binary.Base32 as Base32 |
18 | import qualified Codec.Binary.Base64 as Base64 | 18 | import qualified Codec.Binary.Base64 as Base64 |
19 | #endif | 19 | #endif |
20 | import qualified Codec.Encryption.OpenPGP.ASCIIArmor as ASCIIArmor | ||
21 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | ||
20 | import Control.Applicative (liftA2) | 22 | import Control.Applicative (liftA2) |
21 | import Control.Arrow (first, second) | 23 | import Control.Arrow (first, second) |
22 | import Control.Exception (catch) | 24 | import Control.Exception (catch) |
@@ -299,22 +301,29 @@ isring :: FileType -> Bool | |||
299 | isring (PGPPackets {}) = True | 301 | isring (PGPPackets {}) = True |
300 | isring _ = False | 302 | isring _ = False |
301 | 303 | ||
302 | readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) | 304 | decodePacketList :: L.ByteString -> [Packet] |
303 | readPacketsFromFile ctx fname = do | 305 | decodePacketList 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 | |||
313 | decodeOrFail bs = Right (L.empty,1,decode bs) | ||
316 | #endif | 314 | #endif |
317 | 315 | ||
316 | |||
317 | readPacketsFromFile :: InputFileContext -> InputFile -> IO (PacketsCodec, Message) | ||
318 | readPacketsFromFile 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 | |||
318 | readPacketsFromWallet :: | 327 | readPacketsFromWallet :: |
319 | Maybe Packet | 328 | Maybe Packet |
320 | -> InputFile | 329 | -> InputFile |