From d17ea2bb11255f7e6ae9069d3b58e8f06d5946a5 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Wed, 25 Apr 2012 22:26:57 -0400 Subject: Add multipartMerge --- Codec/Encryption/OpenPGP/ASCIIArmor.hs | 2 ++ Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs (limited to 'Codec') diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor.hs b/Codec/Encryption/OpenPGP/ASCIIArmor.hs index 26d58dd..6d0c172 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor.hs @@ -7,7 +7,9 @@ module Codec.Encryption.OpenPGP.ASCIIArmor ( encode , decode , parseArmor + , multipartMerge ) where import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (encode) import Codec.Encryption.OpenPGP.ASCIIArmor.Decode (decode, parseArmor) +import Codec.Encryption.OpenPGP.ASCIIArmor.Multipart (multipartMerge) diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs new file mode 100644 index 0000000..8719c7c --- /dev/null +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs @@ -0,0 +1,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 -- cgit v1.2.3