summaryrefslogtreecommitdiff
path: root/Codec
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2012-04-25 22:26:57 -0400
committerClint Adams <clint@debian.org>2012-04-25 22:26:57 -0400
commitd17ea2bb11255f7e6ae9069d3b58e8f06d5946a5 (patch)
tree60c0cebd5ae6be14f293ca96e9756351581fa497 /Codec
parent83f494d1c3dbf75054284334bc30e8a1b9825146 (diff)
Add multipartMerge
Diffstat (limited to 'Codec')
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor.hs2
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs24
2 files changed, 26 insertions, 0 deletions
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 (
7 encode 7 encode
8 , decode 8 , decode
9 , parseArmor 9 , parseArmor
10 , multipartMerge
10) where 11) where
11 12
12import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (encode) 13import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (encode)
13import Codec.Encryption.OpenPGP.ASCIIArmor.Decode (decode, parseArmor) 14import Codec.Encryption.OpenPGP.ASCIIArmor.Decode (decode, parseArmor)
15import 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 @@
1-- ASCIIArmor/Multipart.hs: OpenPGP (RFC4880) ASCII armor implementation
2-- Copyright Ⓒ 2012 Clint Adams
3-- This software is released under the terms of the ISC license.
4-- (See the LICENSE file).
5
6module Codec.Encryption.OpenPGP.ASCIIArmor.Multipart (
7 multipartMerge
8) where
9
10import Codec.Encryption.OpenPGP.ASCIIArmor.Types
11
12import Data.ByteString (ByteString)
13import qualified Data.ByteString as B
14
15multipartMerge :: [Armor] -> Armor
16multipartMerge as = go as (Armor ArmorMessage [] B.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' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor
22 go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `B.append` bs)
23 go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `B.append` bs)
24 go' _ _ _ state = state