summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClint Adams <clint@softwarefreedom.org>2012-04-26 16:29:50 -0400
committerClint Adams <clint@softwarefreedom.org>2012-04-26 16:29:50 -0400
commit716dd382221343e5da5daf1a9a8ac40304a7d74b (patch)
tree0a2b7bed56f9ec6564d4a9e918ab4e8fd53c0dc5 /tests
parentd17ea2bb11255f7e6ae9069d3b58e8f06d5946a5 (diff)
Codec for "Cleartext Signatures"
Diffstat (limited to 'tests')
-rw-r--r--tests/data/msg39
-rw-r--r--tests/data/msg3.asc29
-rw-r--r--tests/data/msg3.sigbin0 -> 543 bytes
-rw-r--r--tests/data/msg41
-rw-r--r--tests/data/msg4.asc17
-rw-r--r--tests/data/msg4.sigbin0 -> 543 bytes
-rw-r--r--tests/suite.hs35
7 files changed, 90 insertions, 1 deletions
diff --git a/tests/data/msg3 b/tests/data/msg3
new file mode 100644
index 0000000..e9d15c8
--- /dev/null
+++ b/tests/data/msg3
@@ -0,0 +1,9 @@
1This is a message that will be clearsigned.
2
3From RFC4880, we know that some of these lines should be
4dash-escaped.
5
6-Lines starting with a minus-hyphen MUST be escaped.
7- Lines starting with "From" SHOULD be escaped.
8
9Other lines MAY be escaped.
diff --git a/tests/data/msg3.asc b/tests/data/msg3.asc
new file mode 100644
index 0000000..6d90d30
--- /dev/null
+++ b/tests/data/msg3.asc
@@ -0,0 +1,29 @@
1-----BEGIN PGP SIGNED MESSAGE-----
2Hash: SHA1
3
4This is a message that will be clearsigned.
5
6- From RFC4880, we know that some of these lines should be
7dash-escaped.
8
9- -Lines starting with a minus-hyphen MUST be escaped.
10- - Lines starting with "From" SHOULD be escaped.
11
12Other lines MAY be escaped.
13-----BEGIN PGP SIGNATURE-----
14Version: OpenPrivacy 0.99
15
16iQIcBAEBAgAGBQJPmXqrAAoJEN/7iwtcb1WCG3AQAJ6TBeX12YDI1f/AdtV46quG
17augJYpYZvBbKESGXue1Nv22a7uH4h8LgWRsaEQxMBUwJvlMJfNkjEMAkXQbkj/Og
18J+78bAGMV1GtC5MuwPr8E+M8Z/uHhbzj3fWuUask0Q057u655YIEdlnY4OcZv9jW
19hT+/2kNcC8aw9+kg0I175XNxwBhRXoRKX6dhyAkRSnz7yuQtGXH7kQJAt7TOxxAb
20dud+u5IJixDPebG+NONPfuW5VB8erByW6UPIy4BQBnaxflSD8qJXxCDMWNzOBlYG
21whKXDmlcVgy3J7ghSh2zcFcZhM30Ng49t6k57HOXR9XnI5dskY45yns2nD4kt58/
227anmscGGj0S3pzoUuFAdVIEvziYDhISs35CmTmNh4r4LVuh4R+Zurt3mbe8O6amm
23ZOWZzPsEDX/13B/DnL//70jVhTXUBqDj6MeNj5XHXVbIlfmIyeVLOIXiT/+u1FFt
24+0ERqwFI152GGJJWlikn5bR6P89Xz+04OeTBdxV1fCGt+hlvN6e5X9K15P16QDiq
254COHMZyIyHbtQr92BIj0P46WNsNZJDaoegHl6xtbq60eV3W+LRvgHNphjE+mdIp0
26EV5lBqDGupGYpHkPjZBg0pqASs0Xd3P7SwkoVimtH7mXCPrL4K+o6X8IwsfEMCGY
27Ddej4NK0eolGoz/1sKB0
28=ZShm
29-----END PGP SIGNATURE-----
diff --git a/tests/data/msg3.sig b/tests/data/msg3.sig
new file mode 100644
index 0000000..67ceced
--- /dev/null
+++ b/tests/data/msg3.sig
Binary files differ
diff --git a/tests/data/msg4 b/tests/data/msg4
new file mode 100644
index 0000000..b69b7b6
--- /dev/null
+++ b/tests/data/msg4
@@ -0,0 +1 @@
This message is detach-signed.
diff --git a/tests/data/msg4.asc b/tests/data/msg4.asc
new file mode 100644
index 0000000..d1968f4
--- /dev/null
+++ b/tests/data/msg4.asc
@@ -0,0 +1,17 @@
1-----BEGIN PGP SIGNATURE-----
2Version: GnuPG v1.4.12 (GNU/Linux)
3
4iQIcBAABAgAGBQJPmZE0AAoJEN/7iwtcb1WC6EcQAK+NpDfsgTJgq+5nhZLZQcDC
5+b+8K5eDn+Z/btFZz1h2mF3Y+MpJdgG5fvSSHsYRWiGuT8OBK5wm3vSYnSr8BeA5
6JUJDdhasF7LVosb0ToNiWLbtj9D9iiqmCaPW56Y2u3Ktv5Y4nOAWZw31OGv21B1c
7ptYVv2iy1qPGgnHxYgM5ib37hzKlkTEGKFNMpfYqsMBZyXiKuLpVhEWelawMnCPJ
83b7loOhYvR1Odmolg0dmcFsay7s3uXC/nze+xqTM0Z1HnMxQVW54aixhOoajDO6V
9p7OUUN5g/PBXHvx/gh7gPqgRCazo93rHSgoP//AoEuljrU4W9iNpCEcE5HTdYx0b
10xh10WxWE4VHI8BVt5qhSzPe8BmFRWz+g9CmsJdmhw45W8XxRJMJwoTWzGPcmHTFk
11JTOgJ9/MKcBvYGsBd0wGYq82DbDPdtwGgh5Aa3nz1dxzLCq7qIhOa3VEYKAhCjTx
12UHWnKZrdjSKz8U4D6CECyxlK5UApPc4jWzn3XYCX8s2F84YW7htduE57Yf60bXom
13aefIbDWef1Q4MOUV10h1gyjXtdSiIHvJ0ItvGKmRiXztjhq6+azYN+4RaXzpF5/N
14pqG/DNeTouzMRSzEoLTQ2oBHB8VIbCnP6J2Ck3wPfJZfc6FyCv0gMPQ5pTToll97
156toTAyOHl3pI/inp7IGj
16=TJqj
17-----END PGP SIGNATURE-----
diff --git a/tests/data/msg4.sig b/tests/data/msg4.sig
new file mode 100644
index 0000000..94483e2
--- /dev/null
+++ b/tests/data/msg4.sig
Binary files differ
diff --git a/tests/suite.hs b/tests/suite.hs
index 6fdd816..838a5f3 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -5,6 +5,7 @@ import Test.HUnit
5 5
6import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode, multipartMerge) 6import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode, multipartMerge)
7import Codec.Encryption.OpenPGP.ASCIIArmor.Types 7import Codec.Encryption.OpenPGP.ASCIIArmor.Types
8import Codec.Encryption.OpenPGP.ASCIIArmor.Utils
8 9
9import Data.ByteString (ByteString) 10import Data.ByteString (ByteString)
10import qualified Data.ByteString as B 11import qualified Data.ByteString as B
@@ -35,11 +36,39 @@ testArmorMultipartDecode fp target = do
35 where 36 where
36 getPayload (Armor _ _ pl) = pl 37 getPayload (Armor _ _ pl) = pl
37 38
39testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion
40testClearsignedDecodeBody fp target = do
41 bs <- B.readFile $ "tests/data/" ++ fp
42 tbs <- B.readFile $ "tests/data/" ++ target
43 case decode bs of
44 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
45 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a)
46 where
47 getBody (ClearSigned _ txt _) = txt
48 convertEndings = crlfUnlines . BC8.lines
49
50testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion
51testClearsignedDecodeSig fp target = do
52 bs <- B.readFile $ "tests/data/" ++ fp
53 tbs <- B.readFile $ "tests/data/" ++ target
54 case decode bs of
55 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
56 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a)
57 where
58 getSig (ClearSigned _ _ (Armor _ _ sig)) = sig
59
38testArmorEncode :: [FilePath] -> FilePath -> Assertion 60testArmorEncode :: [FilePath] -> FilePath -> Assertion
39testArmorEncode fps target = do 61testArmorEncode fps target = do
40 bss <- mapM (\fp -> B.readFile $ "tests/data/" ++ fp) fps 62 bss <- mapM (\fp -> B.readFile $ "tests/data/" ++ fp) fps
41 tbs <- B.readFile $ "tests/data/" ++ target 63 tbs <- B.readFile $ "tests/data/" ++ target
42 assertEqual ("literaldata") (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) tbs 64 assertEqual ("literaldata") tbs (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss))
65
66testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion
67testClearsignedEncode ftxt fsig ftarget = do
68 txt <- B.readFile $ "tests/data/" ++ ftxt
69 sig <- B.readFile $ "tests/data/" ++ fsig
70 target <- B.readFile $ "tests/data/" ++ ftarget
71 assertEqual ("clearsigned encode") target (encode [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)])
43 72
44tests = [ 73tests = [
45 testGroup "CRC24" [ 74 testGroup "CRC24" [
@@ -51,9 +80,13 @@ tests = [
51 testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"]) 80 testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"])
52 , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"]) 81 , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"])
53 , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"]) 82 , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"])
83 , testCase "Decode detached signature" (testArmorDecode "msg4.asc" ["msg4.sig"])
54 , testCase "Decode multi-part armor" (testArmorMultipartDecode "msg2.asc" "msg2.pgp") 84 , testCase "Decode multi-part armor" (testArmorMultipartDecode "msg2.asc" "msg2.pgp")
85 , testCase "Decode body of clear-signed" (testClearsignedDecodeBody "msg3.asc" "msg3")
86 , testCase "Decode sig of clear-signed" (testClearsignedDecodeSig "msg3.asc" "msg3.sig")
55 , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc") 87 , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc")
56 , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc") 88 , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc")
89 , testCase "Encode clear-signed sig" (testClearsignedEncode "msg3" "msg3.sig" "msg3.asc")
57 ] 90 ]
58 ] 91 ]
59 92