summaryrefslogtreecommitdiff
path: root/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs
blob: 8719c7ca44e4da108530f0c6060b529e786bec3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- ASCIIArmor/Multipart.hs: OpenPGP (RFC4880) ASCII armor implementation
-- Copyright Ⓒ 2012  Clint Adams
-- This software is released under the terms of the ISC license.
-- (See the LICENSE file).

module Codec.Encryption.OpenPGP.ASCIIArmor.Multipart (
   multipartMerge
) where

import Codec.Encryption.OpenPGP.ASCIIArmor.Types

import Data.ByteString (ByteString)
import qualified Data.ByteString as B

multipartMerge :: [Armor] -> Armor
multipartMerge as = go as (Armor ArmorMessage [] B.empty)
    where
        go :: [Armor] -> Armor -> Armor
        go [] state = state
        go ((Armor at hs bs):as) state = go as (go' at hs bs state)
        go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor
        go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `B.append` bs)
        go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `B.append` bs)
        go' _ _ _ state = state