summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2012-07-27 23:48:27 -0400
committerClint Adams <clint@debian.org>2012-07-27 23:48:27 -0400
commitc708dc4b1d84bc85c52c5c3255f65c62a67ee039 (patch)
tree59dcc5dff95c2803e531e009bd411e85405ac5ee
parent3a9f6d91f4b1e36d92ea18237ae8caf1bb639203 (diff)
Make -Wall-clean and build with -Wall.
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs39
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs3
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs3
-rw-r--r--openpgp-asciiarmor.cabal2
-rw-r--r--tests/suite.hs12
5 files changed, 32 insertions, 27 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
index b1cc5c0..98934a0 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
@@ -17,7 +17,6 @@ import Data.Attoparsec.ByteString (Parser, many1, string, inClass, notInClass, s
17import qualified Data.Attoparsec.ByteString as AS 17import qualified Data.Attoparsec.ByteString as AS
18import qualified Data.Attoparsec.ByteString.Lazy as AL 18import qualified Data.Attoparsec.ByteString.Lazy as AL
19import Data.Attoparsec.ByteString.Char8 (isDigit_w8, anyChar) 19import Data.Attoparsec.ByteString.Char8 (isDigit_w8, anyChar)
20import Data.Attoparsec.Combinator (manyTill)
21import Data.Bits (shiftL) 20import Data.Bits (shiftL)
22import Data.ByteString (ByteString) 21import Data.ByteString (ByteString)
23import qualified Data.ByteString as B 22import qualified Data.ByteString as B
@@ -25,23 +24,21 @@ import qualified Data.ByteString.Lazy as BL
25import qualified Data.ByteString.Char8 as BC8 24import qualified Data.ByteString.Char8 as BC8
26import qualified Data.ByteString.Base64 as Base64 25import qualified Data.ByteString.Base64 as Base64
27import Data.Digest.CRC24 (crc24) 26import Data.Digest.CRC24 (crc24)
28import Data.Serialize (get)
29import Data.Serialize.Get (Get, runGet, getWord8) 27import Data.Serialize.Get (Get, runGet, getWord8)
30import Data.Serialize.Put (runPut, putWord32be)
31import Data.String (IsString, fromString) 28import Data.String (IsString, fromString)
32import Data.Word (Word32) 29import Data.Word (Word32)
33 30
34decode :: IsString e => ByteString -> Either e [Armor] 31decode :: IsString e => ByteString -> Either e [Armor]
35decode bs = go (AS.parse parseArmors bs) 32decode bs = go (AS.parse parseArmors bs)
36 where 33 where
37 go (AS.Fail t c e) = Left (fromString e) 34 go (AS.Fail _ _ e) = Left (fromString e)
38 go (AS.Partial cont) = go (cont B.empty) 35 go (AS.Partial cont) = go (cont B.empty)
39 go (AS.Done _ r) = Right r 36 go (AS.Done _ r) = Right r
40 37
41decodeLazy :: IsString e => BL.ByteString -> Either e [Armor] 38decodeLazy :: IsString e => BL.ByteString -> Either e [Armor]
42decodeLazy bs = go (AL.parse parseArmors bs) 39decodeLazy bs = go (AL.parse parseArmors bs)
43 where 40 where
44 go (AL.Fail t c e) = Left (fromString e) 41 go (AL.Fail _ _ e) = Left (fromString e)
45 go (AL.Done _ r) = Right r 42 go (AL.Done _ r) = Right r
46 43
47parseArmors :: Parser [Armor] 44parseArmors :: Parser [Armor]
@@ -52,10 +49,10 @@ parseArmor = prefixed (clearsigned <|> armor) <?> "armor"
52 49
53clearsigned :: Parser Armor 50clearsigned :: Parser Armor
54clearsigned = do 51clearsigned = do
55 string "-----BEGIN PGP SIGNED MESSAGE-----" <?> "clearsign header" 52 _ <- string "-----BEGIN PGP SIGNED MESSAGE-----" <?> "clearsign header"
56 lineEnding <?> "line ending" 53 _ <- lineEnding <?> "line ending"
57 headers <- armorHeaders <?> "clearsign headers" 54 headers <- armorHeaders <?> "clearsign headers"
58 blankishLine <?> "blank line" 55 _ <- blankishLine <?> "blank line"
59 cleartext <- dashEscapedCleartext 56 cleartext <- dashEscapedCleartext
60 sig <- armor 57 sig <- armor
61 return $ ClearSigned headers (BL.fromChunks [cleartext]) sig 58 return $ ClearSigned headers (BL.fromChunks [cleartext]) sig
@@ -64,18 +61,18 @@ armor :: Parser Armor
64armor = do 61armor = do
65 atype <- beginLine <?> "begin line" 62 atype <- beginLine <?> "begin line"
66 headers <- armorHeaders <?> "headers" 63 headers <- armorHeaders <?> "headers"
67 blankishLine <?> "blank line" 64 _ <- blankishLine <?> "blank line"
68 payload <- base64Data <?> "base64 data" 65 payload <- base64Data <?> "base64 data"
69 endLine atype <?> "end line" 66 _ <- endLine atype <?> "end line"
70 return $ Armor atype headers (BL.fromChunks [payload]) 67 return $ Armor atype headers (BL.fromChunks [payload])
71 68
72beginLine :: Parser ArmorType 69beginLine :: Parser ArmorType
73beginLine = do 70beginLine = do
74 string "-----BEGIN PGP " <?> "leading minus-hyphens" 71 _ <- string "-----BEGIN PGP " <?> "leading minus-hyphens"
75 atype <- pubkey <|> privkey <|> parts <|> message <|> signature 72 atype <- pubkey <|> privkey <|> parts <|> message <|> signature
76 string "-----" <?> "trailing minus-hyphens" 73 _ <- string "-----" <?> "trailing minus-hyphens"
77 many (satisfy (inClass " \t")) <?> "whitespace" 74 _ <- many (satisfy (inClass " \t")) <?> "whitespace"
78 lineEnding <?> "line ending" 75 _ <- lineEnding <?> "line ending"
79 return atype 76 return atype
80 where 77 where
81 message = string "MESSAGE" *> return ArmorMessage 78 message = string "MESSAGE" *> return ArmorMessage
@@ -85,7 +82,7 @@ beginLine = do
85 parts = string "MESSAGE, PART " *> (partsdef <|> partsindef) 82 parts = string "MESSAGE, PART " *> (partsdef <|> partsindef)
86 partsdef = do 83 partsdef = do
87 firstnum <- num 84 firstnum <- num
88 word8 (fromIntegral . fromEnum $ '/') 85 _ <- word8 (fromIntegral . fromEnum $ '/')
89 secondnum <- num 86 secondnum <- num
90 return $ ArmorSplitMessage (BL.pack firstnum) (BL.pack secondnum) 87 return $ ArmorSplitMessage (BL.pack firstnum) (BL.pack secondnum)
91 partsindef = ArmorSplitMessageIndefinite . BL.pack <$> num 88 partsindef = ArmorSplitMessageIndefinite . BL.pack <$> num
@@ -100,9 +97,9 @@ armorHeaders = many armorHeader
100armorHeader :: Parser (String, String) 97armorHeader :: Parser (String, String)
101armorHeader = do 98armorHeader = do
102 key <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) 99 key <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
103 string ": " 100 _ <- string ": "
104 val <- many1 (satisfy (notInClass "\n\r")) 101 val <- many1 (satisfy (notInClass "\n\r"))
105 lineEnding 102 _ <- lineEnding
106 return (w8sToString key, w8sToString val) 103 return (w8sToString key, w8sToString val)
107 where 104 where
108 w8sToString = BC8.unpack . B.pack 105 w8sToString = BC8.unpack . B.pack
@@ -112,7 +109,7 @@ blankishLine = many (satisfy (inClass " \t")) *> lineEnding
112 109
113endLine :: ArmorType -> Parser ByteString 110endLine :: ArmorType -> Parser ByteString
114endLine atype = do 111endLine atype = do
115 string $ "-----END PGP " `B.append` aType atype `B.append` "-----" 112 _ <- string $ "-----END PGP " `B.append` aType atype `B.append` "-----"
116 lineEnding 113 lineEnding
117 114
118aType :: ArmorType -> ByteString 115aType :: ArmorType -> ByteString
@@ -140,16 +137,16 @@ base64Data = do
140 base64Line = do 137 base64Line = do
141 b64 <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")) 138 b64 <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"))
142 pad <- many (word8 (fromIntegral . fromEnum $ '=')) 139 pad <- many (word8 (fromIntegral . fromEnum $ '='))
143 lineEnding 140 _ <- lineEnding
144 let line = B.pack b64 `B.append` B.pack pad 141 let line = B.pack b64 `B.append` B.pack pad
145 case Base64.decode line of 142 case Base64.decode line of
146 Left err -> fail err 143 Left err -> fail err
147 Right bs -> return bs 144 Right bs -> return bs
148 checksumLine :: Parser ByteString 145 checksumLine :: Parser ByteString
149 checksumLine = do 146 checksumLine = do
150 word8 (fromIntegral . fromEnum $ '=') 147 _ <- word8 (fromIntegral . fromEnum $ '=')
151 b64 <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")) 148 b64 <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"))
152 lineEnding 149 _ <- lineEnding
153 let line = B.pack b64 150 let line = B.pack b64
154 case Base64.decode line of 151 case Base64.decode line of
155 Left err -> fail err 152 Left err -> fail err
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
index a1f8bba..c437439 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
@@ -12,13 +12,10 @@ import Codec.Encryption.OpenPGP.ASCIIArmor.Types
12import Data.ByteString.Lazy (ByteString) 12import Data.ByteString.Lazy (ByteString)
13import qualified Data.ByteString as B 13import qualified Data.ByteString as B
14import qualified Data.ByteString.Lazy as BL 14import qualified Data.ByteString.Lazy as BL
15import qualified Data.ByteString.Char8 as BC8
16import qualified Data.ByteString.Lazy.Char8 as BLC8 15import qualified Data.ByteString.Lazy.Char8 as BLC8
17import qualified Data.ByteString.Base64 as Base64 16import qualified Data.ByteString.Base64 as Base64
18import Data.Digest.CRC24 (crc24Lazy) 17import Data.Digest.CRC24 (crc24Lazy)
19import Data.Serialize (put)
20import Data.Serialize.Put (runPutLazy, putWord32be) 18import Data.Serialize.Put (runPutLazy, putWord32be)
21import Data.String (IsString, fromString)
22 19
23encode :: [Armor] -> B.ByteString 20encode :: [Armor] -> B.ByteString
24encode = B.concat . BL.toChunks . encodeLazy 21encode = B.concat . BL.toChunks . encodeLazy
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs
index 385074f..0334c7e 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs
@@ -13,11 +13,12 @@ import Data.ByteString.Lazy (ByteString)
13import qualified Data.ByteString.Lazy as BL 13import qualified Data.ByteString.Lazy as BL
14 14
15multipartMerge :: [Armor] -> Armor 15multipartMerge :: [Armor] -> Armor
16multipartMerge as = go as (Armor ArmorMessage [] BL.empty) 16multipartMerge as' = go as' (Armor ArmorMessage [] BL.empty)
17 where 17 where
18 go :: [Armor] -> Armor -> Armor 18 go :: [Armor] -> Armor -> Armor
19 go [] state = state 19 go [] state = state
20 go (Armor at hs bs:as) state = go as (go' at hs bs state) 20 go (Armor at hs bs:as) state = go as (go' at hs bs state)
21 go _ _ = error "This shouldn't happen."
21 go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor 22 go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor
22 go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs) 23 go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs)
23 go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs) 24 go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs)
diff --git a/openpgp-asciiarmor.cabal b/openpgp-asciiarmor.cabal
index 55a97f6..74711e7 100644
--- a/openpgp-asciiarmor.cabal
+++ b/openpgp-asciiarmor.cabal
@@ -36,6 +36,7 @@ Library
36 Other-Modules: Data.Digest.CRC24 36 Other-Modules: Data.Digest.CRC24
37 , Codec.Encryption.OpenPGP.ASCIIArmor.Multipart 37 , Codec.Encryption.OpenPGP.ASCIIArmor.Multipart
38 , Codec.Encryption.OpenPGP.ASCIIArmor.Utils 38 , Codec.Encryption.OpenPGP.ASCIIArmor.Utils
39 Ghc-options: -Wall
39 Build-depends: attoparsec 40 Build-depends: attoparsec
40 , base > 4 && < 5 41 , base > 4 && < 5
41 , base64-bytestring 42 , base64-bytestring
@@ -47,6 +48,7 @@ Library
47Test-Suite tests 48Test-Suite tests
48 type: exitcode-stdio-1.0 49 type: exitcode-stdio-1.0
49 main-is: tests/suite.hs 50 main-is: tests/suite.hs
51 Ghc-options: -Wall
50 Build-depends: attoparsec 52 Build-depends: attoparsec
51 , base > 4 && < 5 53 , base > 4 && < 5
52 , base64-bytestring 54 , base64-bytestring
diff --git a/tests/suite.hs b/tests/suite.hs
index ffcbc17..5ad3d05 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -1,7 +1,7 @@
1import Test.Framework (defaultMain, testGroup) 1import Test.Framework (defaultMain, testGroup, Test)
2import Test.Framework.Providers.HUnit 2import Test.Framework.Providers.HUnit
3 3
4import Test.HUnit 4import Test.HUnit (Assertion, assertEqual, assertFailure)
5 5
6import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) 6import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge)
7import Codec.Encryption.OpenPGP.ASCIIArmor.Types 7import Codec.Encryption.OpenPGP.ASCIIArmor.Types
@@ -27,6 +27,7 @@ testArmorDecode fp targets = do
27 Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) 27 Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as)
28 where 28 where
29 getPayload (Armor _ _ pl) = pl 29 getPayload (Armor _ _ pl) = pl
30 getPayload _ = error "This should not happen."
30 31
31testArmorMultipartDecode :: FilePath -> FilePath -> Assertion 32testArmorMultipartDecode :: FilePath -> FilePath -> Assertion
32testArmorMultipartDecode fp target = do 33testArmorMultipartDecode fp target = do
@@ -37,6 +38,7 @@ testArmorMultipartDecode fp target = do
37 Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) 38 Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as))
38 where 39 where
39 getPayload (Armor _ _ pl) = pl 40 getPayload (Armor _ _ pl) = pl
41 getPayload _ = error "This should not happen."
40 42
41testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion 43testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion
42testClearsignedDecodeBody fp target = do 44testClearsignedDecodeBody fp target = do
@@ -45,8 +47,10 @@ testClearsignedDecodeBody fp target = do
45 case decodeLazy bs of 47 case decodeLazy bs of
46 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 48 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
47 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) 49 Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a)
50 _ -> assertFailure "This shouldn't happen."
48 where 51 where
49 getBody (ClearSigned _ txt _) = txt 52 getBody (ClearSigned _ txt _) = txt
53 getBody _ = error "This should not happen."
50 convertEndings = crlfUnlinesLazy . BLC8.lines 54 convertEndings = crlfUnlinesLazy . BLC8.lines
51 55
52testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion 56testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion
@@ -56,8 +60,10 @@ testClearsignedDecodeSig fp target = do
56 case decodeLazy bs of 60 case decodeLazy bs of
57 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp 61 Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp
58 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) 62 Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a)
63 _ -> assertFailure "This shouldn't happen."
59 where 64 where
60 getSig (ClearSigned _ _ (Armor _ _ sig)) = sig 65 getSig (ClearSigned _ _ (Armor _ _ sig)) = sig
66 getSig _ = error "This should not happen."
61 67
62testArmorEncode :: [FilePath] -> FilePath -> Assertion 68testArmorEncode :: [FilePath] -> FilePath -> Assertion
63testArmorEncode fps target = do 69testArmorEncode fps target = do
@@ -83,6 +89,7 @@ testStrictEncode fp = do
83 let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)] 89 let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)]
84 assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)]) 90 assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)])
85 91
92tests :: [Test]
86tests = [ 93tests = [
87 testGroup "CRC24" [ 94 testGroup "CRC24" [
88 testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) 95 testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698)
@@ -105,4 +112,5 @@ tests = [
105 ] 112 ]
106 ] 113 ]
107 114
115main :: IO ()
108main = defaultMain tests 116main = defaultMain tests