summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2012-04-25 19:26:58 -0400
committerClint Adams <clint@debian.org>2012-04-25 19:27:26 -0400
commit4a0bb47803be6be43b8bb5c62f302019a25f9fd1 (patch)
tree53c0f2ae494136395401d6dc73f4409cba4f0637
parentf06c3f713f99c9ea09a76728ffce2c6e1c957070 (diff)
Encode multiple Armors into one ByteString.
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor.hs4
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs5
-rw-r--r--openpgp-asciiarmor.cabal1
-rw-r--r--tests/data/msg1c.asc21
-rw-r--r--tests/suite.hs13
5 files changed, 35 insertions, 9 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor.hs b/Codec/Encryption/OpenPGP/ASCIIArmor.hs
index 075a481..26d58dd 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor.hs
@@ -4,10 +4,10 @@
4-- (See the LICENSE file). 4-- (See the LICENSE file).
5 5
6module Codec.Encryption.OpenPGP.ASCIIArmor ( 6module Codec.Encryption.OpenPGP.ASCIIArmor (
7 armor 7 encode
8 , decode 8 , decode
9 , parseArmor 9 , parseArmor
10) where 10) where
11 11
12import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (armor) 12import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (encode)
13import Codec.Encryption.OpenPGP.ASCIIArmor.Decode (decode, parseArmor) 13import Codec.Encryption.OpenPGP.ASCIIArmor.Decode (decode, parseArmor)
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
index 8853be3..99d4d54 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
@@ -4,7 +4,7 @@
4-- (See the LICENSE file). 4-- (See the LICENSE file).
5 5
6module Codec.Encryption.OpenPGP.ASCIIArmor.Encode ( 6module Codec.Encryption.OpenPGP.ASCIIArmor.Encode (
7 armor 7 encode
8) where 8) where
9 9
10import Codec.Encryption.OpenPGP.ASCIIArmor.Types 10import Codec.Encryption.OpenPGP.ASCIIArmor.Types
@@ -17,6 +17,9 @@ import Data.Serialize (put)
17import Data.Serialize.Put (runPut, putWord32be) 17import Data.Serialize.Put (runPut, putWord32be)
18import Data.String (IsString, fromString) 18import Data.String (IsString, fromString)
19 19
20encode :: (Integral a, Show a) => [Armor a] -> ByteString
21encode = B.concat . map armor
22
20armor :: (Integral a, Show a) => Armor a -> ByteString 23armor :: (Integral a, Show a) => Armor a -> ByteString
21armor (Armor atype ahs bs) = beginLine atype `B.append` armorHeaders ahs `B.append` blankLine `B.append` armorData bs `B.append` armorChecksum bs `B.append` endLine atype 24armor (Armor atype ahs bs) = beginLine atype `B.append` armorHeaders ahs `B.append` blankLine `B.append` armorData bs `B.append` armorChecksum bs `B.append` endLine atype
22 25
diff --git a/openpgp-asciiarmor.cabal b/openpgp-asciiarmor.cabal
index ff2289a..e161d6f 100644
--- a/openpgp-asciiarmor.cabal
+++ b/openpgp-asciiarmor.cabal
@@ -14,6 +14,7 @@ Extra-source-files: tests/suite.hs
14 , tests/data/msg1.asc 14 , tests/data/msg1.asc
15 , tests/data/msg1a.asc 15 , tests/data/msg1a.asc
16 , tests/data/msg1b.asc 16 , tests/data/msg1b.asc
17 , tests/data/msg1c.asc
17 , tests/data/msg1.gpg 18 , tests/data/msg1.gpg
18 19
19Cabal-version: >= 1.10 20Cabal-version: >= 1.10
diff --git a/tests/data/msg1c.asc b/tests/data/msg1c.asc
new file mode 100644
index 0000000..c7ac785
--- /dev/null
+++ b/tests/data/msg1c.asc
@@ -0,0 +1,21 @@
1-----BEGIN PGP MESSAGE-----
2Version: OpenPrivacy 0.99
3
4yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
5vBSFjNSiVHsuAA==
6=njUN
7-----END PGP MESSAGE-----
8-----BEGIN PGP MESSAGE-----
9Version: OpenPrivacy 0.99
10
11yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
12vBSFjNSiVHsuAA==
13=njUN
14-----END PGP MESSAGE-----
15-----BEGIN PGP MESSAGE-----
16Version: OpenPrivacy 0.99
17
18yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
19vBSFjNSiVHsuAA==
20=njUN
21-----END PGP MESSAGE-----
diff --git a/tests/suite.hs b/tests/suite.hs
index 45a2fb2..a843664 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -3,7 +3,7 @@ import Test.Framework.Providers.HUnit
3 3
4import Test.HUnit 4import Test.HUnit
5 5
6import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decode) 6import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode)
7import Codec.Encryption.OpenPGP.ASCIIArmor.Types 7import Codec.Encryption.OpenPGP.ASCIIArmor.Types
8 8
9import Data.ByteString (ByteString) 9import Data.ByteString (ByteString)
@@ -25,11 +25,11 @@ testArmorDecode fp targets = do
25 where 25 where
26 getPayload (Armor _ _ pl) = pl 26 getPayload (Armor _ _ pl) = pl
27 27
28testArmorEncode :: FilePath -> FilePath -> Assertion 28testArmorEncode :: [FilePath] -> FilePath -> Assertion
29testArmorEncode fp target = do 29testArmorEncode fps target = do
30 bs <- B.readFile $ "tests/data/" ++ fp 30 bss <- mapM (\fp -> B.readFile $ "tests/data/" ++ fp) fps
31 tbs <- B.readFile $ "tests/data/" ++ target 31 tbs <- B.readFile $ "tests/data/" ++ target
32 assertEqual ("literaldata") (armor (Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs)) tbs 32 assertEqual ("literaldata") (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) tbs
33 33
34tests = [ 34tests = [
35 testGroup "CRC24" [ 35 testGroup "CRC24" [
@@ -41,7 +41,8 @@ tests = [
41 testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"]) 41 testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"])
42 , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"]) 42 , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"])
43 , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"]) 43 , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"])
44 , testCase "Encode sample armor" (testArmorEncode "msg1.gpg" "msg1.asc") 44 , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc")
45 , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc")
45 ] 46 ]
46 ] 47 ]
47 48