Debian Codegraph @

Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs

raw
1 -- ASCIIArmor/Multipart.hs: OpenPGP (RFC4880) ASCII armor implementation
2 -- Copyright © 2012 Clint Adams
3 -- This software is released under the terms of the Expat license.
4 -- (See the LICENSE file).
5
6 module Codec.Encryption.OpenPGP.ASCIIArmor.Multipart (
7 multipartMerge
8 ) where
9
10 import Codec.Encryption.OpenPGP.ASCIIArmor.Types
11
12 import Data.ByteString.Lazy (ByteString)
13 import qualified Data.ByteString.Lazy as BL
14
15 multipartMerge :: [Armor] -> Armor
16 multipartMerge as' = go as' (Armor ArmorMessage [] BL.empty)
17 where
18 go :: [Armor] -> Armor -> Armor
19 go [] state = state
20 go (Armor at hs bs:as) state = go as (go' at hs bs state)
21 go _ _ = error "This shouldn't happen."
22 go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor
23 go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs)
24 go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs)
25 go' _ _ _ state = state