diff options
author | Clint Adams <clint@debian.org> | 2012-07-27 23:48:27 -0400 |
---|---|---|
committer | Clint Adams <clint@debian.org> | 2012-07-27 23:48:27 -0400 |
commit | c708dc4b1d84bc85c52c5c3255f65c62a67ee039 (patch) | |
tree | 59dcc5dff95c2803e531e009bd411e85405ac5ee | |
parent | 3a9f6d91f4b1e36d92ea18237ae8caf1bb639203 (diff) |
Make -Wall-clean and build with -Wall.
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | 39 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | 3 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs | 3 | ||||
-rw-r--r-- | openpgp-asciiarmor.cabal | 2 | ||||
-rw-r--r-- | tests/suite.hs | 12 |
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 | |||
17 | import qualified Data.Attoparsec.ByteString as AS | 17 | import qualified Data.Attoparsec.ByteString as AS |
18 | import qualified Data.Attoparsec.ByteString.Lazy as AL | 18 | import qualified Data.Attoparsec.ByteString.Lazy as AL |
19 | import Data.Attoparsec.ByteString.Char8 (isDigit_w8, anyChar) | 19 | import Data.Attoparsec.ByteString.Char8 (isDigit_w8, anyChar) |
20 | import Data.Attoparsec.Combinator (manyTill) | ||
21 | import Data.Bits (shiftL) | 20 | import Data.Bits (shiftL) |
22 | import Data.ByteString (ByteString) | 21 | import Data.ByteString (ByteString) |
23 | import qualified Data.ByteString as B | 22 | import qualified Data.ByteString as B |
@@ -25,23 +24,21 @@ import qualified Data.ByteString.Lazy as BL | |||
25 | import qualified Data.ByteString.Char8 as BC8 | 24 | import qualified Data.ByteString.Char8 as BC8 |
26 | import qualified Data.ByteString.Base64 as Base64 | 25 | import qualified Data.ByteString.Base64 as Base64 |
27 | import Data.Digest.CRC24 (crc24) | 26 | import Data.Digest.CRC24 (crc24) |
28 | import Data.Serialize (get) | ||
29 | import Data.Serialize.Get (Get, runGet, getWord8) | 27 | import Data.Serialize.Get (Get, runGet, getWord8) |
30 | import Data.Serialize.Put (runPut, putWord32be) | ||
31 | import Data.String (IsString, fromString) | 28 | import Data.String (IsString, fromString) |
32 | import Data.Word (Word32) | 29 | import Data.Word (Word32) |
33 | 30 | ||
34 | decode :: IsString e => ByteString -> Either e [Armor] | 31 | decode :: IsString e => ByteString -> Either e [Armor] |
35 | decode bs = go (AS.parse parseArmors bs) | 32 | decode 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 | ||
41 | decodeLazy :: IsString e => BL.ByteString -> Either e [Armor] | 38 | decodeLazy :: IsString e => BL.ByteString -> Either e [Armor] |
42 | decodeLazy bs = go (AL.parse parseArmors bs) | 39 | decodeLazy 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 | ||
47 | parseArmors :: Parser [Armor] | 44 | parseArmors :: Parser [Armor] |
@@ -52,10 +49,10 @@ parseArmor = prefixed (clearsigned <|> armor) <?> "armor" | |||
52 | 49 | ||
53 | clearsigned :: Parser Armor | 50 | clearsigned :: Parser Armor |
54 | clearsigned = do | 51 | clearsigned = 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 | |||
64 | armor = do | 61 | armor = 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 | ||
72 | beginLine :: Parser ArmorType | 69 | beginLine :: Parser ArmorType |
73 | beginLine = do | 70 | beginLine = 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 | |||
100 | armorHeader :: Parser (String, String) | 97 | armorHeader :: Parser (String, String) |
101 | armorHeader = do | 98 | armorHeader = 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 | ||
113 | endLine :: ArmorType -> Parser ByteString | 110 | endLine :: ArmorType -> Parser ByteString |
114 | endLine atype = do | 111 | endLine 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 | ||
118 | aType :: ArmorType -> ByteString | 115 | aType :: 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 | |||
12 | import Data.ByteString.Lazy (ByteString) | 12 | import Data.ByteString.Lazy (ByteString) |
13 | import qualified Data.ByteString as B | 13 | import qualified Data.ByteString as B |
14 | import qualified Data.ByteString.Lazy as BL | 14 | import qualified Data.ByteString.Lazy as BL |
15 | import qualified Data.ByteString.Char8 as BC8 | ||
16 | import qualified Data.ByteString.Lazy.Char8 as BLC8 | 15 | import qualified Data.ByteString.Lazy.Char8 as BLC8 |
17 | import qualified Data.ByteString.Base64 as Base64 | 16 | import qualified Data.ByteString.Base64 as Base64 |
18 | import Data.Digest.CRC24 (crc24Lazy) | 17 | import Data.Digest.CRC24 (crc24Lazy) |
19 | import Data.Serialize (put) | ||
20 | import Data.Serialize.Put (runPutLazy, putWord32be) | 18 | import Data.Serialize.Put (runPutLazy, putWord32be) |
21 | import Data.String (IsString, fromString) | ||
22 | 19 | ||
23 | encode :: [Armor] -> B.ByteString | 20 | encode :: [Armor] -> B.ByteString |
24 | encode = B.concat . BL.toChunks . encodeLazy | 21 | encode = 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) | |||
13 | import qualified Data.ByteString.Lazy as BL | 13 | import qualified Data.ByteString.Lazy as BL |
14 | 14 | ||
15 | multipartMerge :: [Armor] -> Armor | 15 | multipartMerge :: [Armor] -> Armor |
16 | multipartMerge as = go as (Armor ArmorMessage [] BL.empty) | 16 | multipartMerge 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 | |||
47 | Test-Suite tests | 48 | Test-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 @@ | |||
1 | import Test.Framework (defaultMain, testGroup) | 1 | import Test.Framework (defaultMain, testGroup, Test) |
2 | import Test.Framework.Providers.HUnit | 2 | import Test.Framework.Providers.HUnit |
3 | 3 | ||
4 | import Test.HUnit | 4 | import Test.HUnit (Assertion, assertEqual, assertFailure) |
5 | 5 | ||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) | 6 | import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) |
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 7 | import 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 | ||
31 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion | 32 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion |
32 | testArmorMultipartDecode fp target = do | 33 | testArmorMultipartDecode 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 | ||
41 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion | 43 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion |
42 | testClearsignedDecodeBody fp target = do | 44 | testClearsignedDecodeBody 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 | ||
52 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion | 56 | testClearsignedDecodeSig :: 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 | ||
62 | testArmorEncode :: [FilePath] -> FilePath -> Assertion | 68 | testArmorEncode :: [FilePath] -> FilePath -> Assertion |
63 | testArmorEncode fps target = do | 69 | testArmorEncode 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 | ||
92 | tests :: [Test] | ||
86 | tests = [ | 93 | tests = [ |
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 | ||
115 | main :: IO () | ||
108 | main = defaultMain tests | 116 | main = defaultMain tests |