diff options
author | Clint Adams <clint@debian.org> | 2012-04-25 19:26:58 -0400 |
---|---|---|
committer | Clint Adams <clint@debian.org> | 2012-04-25 19:27:26 -0400 |
commit | 4a0bb47803be6be43b8bb5c62f302019a25f9fd1 (patch) | |
tree | 53c0f2ae494136395401d6dc73f4409cba4f0637 | |
parent | f06c3f713f99c9ea09a76728ffce2c6e1c957070 (diff) |
Encode multiple Armors into one ByteString.
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor.hs | 4 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | 5 | ||||
-rw-r--r-- | openpgp-asciiarmor.cabal | 1 | ||||
-rw-r--r-- | tests/data/msg1c.asc | 21 | ||||
-rw-r--r-- | tests/suite.hs | 13 |
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 | ||
6 | module Codec.Encryption.OpenPGP.ASCIIArmor ( | 6 | module Codec.Encryption.OpenPGP.ASCIIArmor ( |
7 | armor | 7 | encode |
8 | , decode | 8 | , decode |
9 | , parseArmor | 9 | , parseArmor |
10 | ) where | 10 | ) where |
11 | 11 | ||
12 | import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (armor) | 12 | import Codec.Encryption.OpenPGP.ASCIIArmor.Encode (encode) |
13 | import Codec.Encryption.OpenPGP.ASCIIArmor.Decode (decode, parseArmor) | 13 | import 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 | ||
6 | module Codec.Encryption.OpenPGP.ASCIIArmor.Encode ( | 6 | module Codec.Encryption.OpenPGP.ASCIIArmor.Encode ( |
7 | armor | 7 | encode |
8 | ) where | 8 | ) where |
9 | 9 | ||
10 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 10 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
@@ -17,6 +17,9 @@ import Data.Serialize (put) | |||
17 | import Data.Serialize.Put (runPut, putWord32be) | 17 | import Data.Serialize.Put (runPut, putWord32be) |
18 | import Data.String (IsString, fromString) | 18 | import Data.String (IsString, fromString) |
19 | 19 | ||
20 | encode :: (Integral a, Show a) => [Armor a] -> ByteString | ||
21 | encode = B.concat . map armor | ||
22 | |||
20 | armor :: (Integral a, Show a) => Armor a -> ByteString | 23 | armor :: (Integral a, Show a) => Armor a -> ByteString |
21 | armor (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 | 24 | armor (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 | ||
19 | Cabal-version: >= 1.10 | 20 | Cabal-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----- | ||
2 | Version: OpenPrivacy 0.99 | ||
3 | |||
4 | yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS | ||
5 | vBSFjNSiVHsuAA== | ||
6 | =njUN | ||
7 | -----END PGP MESSAGE----- | ||
8 | -----BEGIN PGP MESSAGE----- | ||
9 | Version: OpenPrivacy 0.99 | ||
10 | |||
11 | yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS | ||
12 | vBSFjNSiVHsuAA== | ||
13 | =njUN | ||
14 | -----END PGP MESSAGE----- | ||
15 | -----BEGIN PGP MESSAGE----- | ||
16 | Version: OpenPrivacy 0.99 | ||
17 | |||
18 | yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS | ||
19 | vBSFjNSiVHsuAA== | ||
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 | ||
4 | import Test.HUnit | 4 | import Test.HUnit |
5 | 5 | ||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (armor, decode) | 6 | import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode) |
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
8 | 8 | ||
9 | import Data.ByteString (ByteString) | 9 | import 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 | ||
28 | testArmorEncode :: FilePath -> FilePath -> Assertion | 28 | testArmorEncode :: [FilePath] -> FilePath -> Assertion |
29 | testArmorEncode fp target = do | 29 | testArmorEncode 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 | ||
34 | tests = [ | 34 | tests = [ |
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 | ||