summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-04-25 17:19:07 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-04-25 17:19:07 -0500
commit6b743222684f2b8151dfbdef42f0dc890e590c41 (patch)
tree77b5ae031d2b863f03399ba9a5b56ba4478d2ab2 /tests
parent7b3232778f284dd4dd3a6f3287bcbe1fbe10b010 (diff)
Split OpenPGP.Crypto out into a seperate package
Diffstat (limited to 'tests')
-rw-r--r--tests/data/encryption-sym-aes256.gpg1
-rw-r--r--tests/data/encryption-sym-cast5.gpgbin72 -> 0 bytes
-rw-r--r--tests/data/encryption.gpgbin860 -> 0 bytes
-rw-r--r--tests/data/msg1.asc7
-rw-r--r--tests/suite.hs57
5 files changed, 5 insertions, 60 deletions
diff --git a/tests/data/encryption-sym-aes256.gpg b/tests/data/encryption-sym-aes256.gpg
deleted file mode 100644
index 264ae11..0000000
--- a/tests/data/encryption-sym-aes256.gpg
+++ /dev/null
@@ -1 +0,0 @@
1  '6*W`VLEQjNp(Y3N*?!M**ۈ; hL2+!x̄&&\J{q<16.-D ޿ \ No newline at end of file
diff --git a/tests/data/encryption-sym-cast5.gpg b/tests/data/encryption-sym-cast5.gpg
deleted file mode 100644
index 2c552ac..0000000
--- a/tests/data/encryption-sym-cast5.gpg
+++ /dev/null
Binary files differ
diff --git a/tests/data/encryption.gpg b/tests/data/encryption.gpg
deleted file mode 100644
index 9781572..0000000
--- a/tests/data/encryption.gpg
+++ /dev/null
Binary files differ
diff --git a/tests/data/msg1.asc b/tests/data/msg1.asc
deleted file mode 100644
index 832d3bb..0000000
--- a/tests/data/msg1.asc
+++ /dev/null
@@ -1,7 +0,0 @@
1-----BEGIN PGP MESSAGE-----
2Version: OpenPrivacy 0.99
3
4yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
5vBSFjNSiVHsuAA==
6=njUN
7-----END PGP MESSAGE-----
diff --git a/tests/suite.hs b/tests/suite.hs
index 7ea5e57..ad7a8f2 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -7,9 +7,7 @@ import Test.HUnit hiding (Test)
7import Data.Word 7import Data.Word
8import Data.Binary 8import Data.Binary
9import qualified Data.OpenPGP as OpenPGP 9import qualified Data.OpenPGP as OpenPGP
10import qualified Data.OpenPGP.Crypto as OpenPGP
11import qualified Data.ByteString.Lazy as LZ 10import qualified Data.ByteString.Lazy as LZ
12import qualified Data.ByteString.Lazy.UTF8 as LZ (fromString)
13 11
14instance Arbitrary OpenPGP.HashAlgorithm where 12instance Arbitrary OpenPGP.HashAlgorithm where
15 arbitrary = elements [OpenPGP.MD5, OpenPGP.SHA1, OpenPGP.SHA256, OpenPGP.SHA384, OpenPGP.SHA512] 13 arbitrary = elements [OpenPGP.MD5, OpenPGP.SHA1, OpenPGP.SHA256, OpenPGP.SHA384, OpenPGP.SHA512]
@@ -18,8 +16,8 @@ testSerialization :: FilePath -> Assertion
18testSerialization fp = do 16testSerialization fp = do
19 bs <- LZ.readFile $ "tests/data/" ++ fp 17 bs <- LZ.readFile $ "tests/data/" ++ fp
20 nullShield "First" (decode bs) (\firstpass -> 18 nullShield "First" (decode bs) (\firstpass ->
21 nullShield "Second" (decode $ encode firstpass) (\secondpass -> 19 nullShield "Second" (decode $ encode firstpass) (
22 assertEqual ("for " ++ fp) firstpass secondpass 20 assertEqual ("for " ++ fp) firstpass
23 ) 21 )
24 ) 22 )
25 where 23 where
@@ -27,38 +25,12 @@ testSerialization fp = do
27 assertFailure $ pass ++ " pass of " ++ fp ++ " decoded to nothing." 25 assertFailure $ pass ++ " pass of " ++ fp ++ " decoded to nothing."
28 nullShield _ m f = f m 26 nullShield _ m f = f m
29 27
30testFingerprint :: FilePath -> String -> Assertion
31testFingerprint fp kf = do
32 bs <- LZ.readFile $ "tests/data/" ++ fp
33 let (OpenPGP.Message [packet]) = decode bs
34 assertEqual ("for " ++ fp) kf (OpenPGP.fingerprint packet)
35
36testVerifyMessage :: FilePath -> FilePath -> Assertion
37testVerifyMessage keyring message = do
38 keys <- fmap decode $ LZ.readFile $ "tests/data/" ++ keyring
39 m <- fmap decode $ LZ.readFile $ "tests/data/" ++ message
40 let verification = OpenPGP.verify keys m 0
41 assertEqual (keyring ++ " for " ++ message) True verification
42
43prop_sign_and_verify :: OpenPGP.Message -> String -> OpenPGP.HashAlgorithm -> String -> String -> Bool
44prop_sign_and_verify secring kid halgo filename msg =
45 let
46 m = OpenPGP.LiteralDataPacket {
47 OpenPGP.format = 'u',
48 OpenPGP.filename = filename,
49 OpenPGP.timestamp = 12341234,
50 OpenPGP.content = LZ.fromString msg
51 }
52 sig = OpenPGP.sign secring (OpenPGP.Message [m]) halgo kid 12341234
53 in
54 OpenPGP.verify secring (OpenPGP.Message [m,sig]) 0
55
56prop_s2k_count :: Word8 -> Bool 28prop_s2k_count :: Word8 -> Bool
57prop_s2k_count c = 29prop_s2k_count c =
58 c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c) 30 c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c)
59 31
60tests :: OpenPGP.Message -> [Test] 32tests :: [Test]
61tests secring = 33tests =
62 [ 34 [
63 testGroup "Serialization" [ 35 testGroup "Serialization" [
64 testCase "000001-006.public_key" (testSerialization "000001-006.public_key"), 36 testCase "000001-006.public_key" (testSerialization "000001-006.public_key"),
@@ -148,29 +120,10 @@ tests secring =
148 testCase "uncompressed-ops-dsa.gpg" (testSerialization "uncompressed-ops-dsa.gpg"), 120 testCase "uncompressed-ops-dsa.gpg" (testSerialization "uncompressed-ops-dsa.gpg"),
149 testCase "uncompressed-ops-rsa.gpg" (testSerialization "uncompressed-ops-rsa.gpg") 121 testCase "uncompressed-ops-rsa.gpg" (testSerialization "uncompressed-ops-rsa.gpg")
150 ], 122 ],
151 testGroup "Fingerprint" [
152 testCase "000001-006.public_key" (testFingerprint "000001-006.public_key" "421F28FEAAD222F856C8FFD5D4D54EA16F87040E"),
153 testCase "000016-006.public_key" (testFingerprint "000016-006.public_key" "AF95E4D7BAC521EE9740BED75E9F1523413262DC"),
154 testCase "000027-006.public_key" (testFingerprint "000027-006.public_key" "1EB20B2F5A5CC3BEAFD6E5CB7732CF988A63EA86"),
155 testCase "000035-006.public_key" (testFingerprint "000035-006.public_key" "CB7933459F59C70DF1C3FBEEDEDC3ECF689AF56D")
156 ],
157 testGroup "Message verification" [
158 --testCase "uncompressed-ops-dsa" (testVerifyMessage "pubring.gpg" "uncompressed-ops-dsa.gpg"),
159 --testCase "uncompressed-ops-dsa-sha384" (testVerifyMessage "pubring.gpg" "uncompressed-ops-dsa-sha384.txt.gpg"),
160 testCase "uncompressed-ops-rsa" (testVerifyMessage "pubring.gpg" "uncompressed-ops-rsa.gpg"),
161 testCase "compressedsig" (testVerifyMessage "pubring.gpg" "compressedsig.gpg"),
162 testCase "compressedsig-zlib" (testVerifyMessage "pubring.gpg" "compressedsig-zlib.gpg"),
163 testCase "compressedsig-bzip2" (testVerifyMessage "pubring.gpg" "compressedsig-bzip2.gpg")
164 ],
165 testGroup "Signing" [
166 testProperty "Crypto signatures verify" (prop_sign_and_verify secring "FEF8AFA0F661C3EE")
167 ],
168 testGroup "S2K count" [ 123 testGroup "S2K count" [
169 testProperty "S2K count encode reverses decode" prop_s2k_count 124 testProperty "S2K count encode reverses decode" prop_s2k_count
170 ] 125 ]
171 ] 126 ]
172 127
173main :: IO () 128main :: IO ()
174main = do 129main = defaultMain tests
175 secring <- fmap decode $ LZ.readFile "tests/data/secring.gpg"
176 defaultMain (tests secring)