From c708dc4b1d84bc85c52c5c3255f65c62a67ee039 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Fri, 27 Jul 2012 23:48:27 -0400 Subject: Make -Wall-clean and build with -Wall. --- Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | 39 +++++++++++------------- Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | 3 -- Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs | 3 +- openpgp-asciiarmor.cabal | 2 ++ 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 import qualified Data.Attoparsec.ByteString as AS import qualified Data.Attoparsec.ByteString.Lazy as AL import Data.Attoparsec.ByteString.Char8 (isDigit_w8, anyChar) -import Data.Attoparsec.Combinator (manyTill) import Data.Bits (shiftL) import Data.ByteString (ByteString) import qualified Data.ByteString as B @@ -25,23 +24,21 @@ import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Char8 as BC8 import qualified Data.ByteString.Base64 as Base64 import Data.Digest.CRC24 (crc24) -import Data.Serialize (get) import Data.Serialize.Get (Get, runGet, getWord8) -import Data.Serialize.Put (runPut, putWord32be) import Data.String (IsString, fromString) import Data.Word (Word32) decode :: IsString e => ByteString -> Either e [Armor] decode bs = go (AS.parse parseArmors bs) where - go (AS.Fail t c e) = Left (fromString e) + go (AS.Fail _ _ e) = Left (fromString e) go (AS.Partial cont) = go (cont B.empty) go (AS.Done _ r) = Right r decodeLazy :: IsString e => BL.ByteString -> Either e [Armor] decodeLazy bs = go (AL.parse parseArmors bs) where - go (AL.Fail t c e) = Left (fromString e) + go (AL.Fail _ _ e) = Left (fromString e) go (AL.Done _ r) = Right r parseArmors :: Parser [Armor] @@ -52,10 +49,10 @@ parseArmor = prefixed (clearsigned <|> armor) "armor" clearsigned :: Parser Armor clearsigned = do - string "-----BEGIN PGP SIGNED MESSAGE-----" "clearsign header" - lineEnding "line ending" + _ <- string "-----BEGIN PGP SIGNED MESSAGE-----" "clearsign header" + _ <- lineEnding "line ending" headers <- armorHeaders "clearsign headers" - blankishLine "blank line" + _ <- blankishLine "blank line" cleartext <- dashEscapedCleartext sig <- armor return $ ClearSigned headers (BL.fromChunks [cleartext]) sig @@ -64,18 +61,18 @@ armor :: Parser Armor armor = do atype <- beginLine "begin line" headers <- armorHeaders "headers" - blankishLine "blank line" + _ <- blankishLine "blank line" payload <- base64Data "base64 data" - endLine atype "end line" + _ <- endLine atype "end line" return $ Armor atype headers (BL.fromChunks [payload]) beginLine :: Parser ArmorType beginLine = do - string "-----BEGIN PGP " "leading minus-hyphens" + _ <- string "-----BEGIN PGP " "leading minus-hyphens" atype <- pubkey <|> privkey <|> parts <|> message <|> signature - string "-----" "trailing minus-hyphens" - many (satisfy (inClass " \t")) "whitespace" - lineEnding "line ending" + _ <- string "-----" "trailing minus-hyphens" + _ <- many (satisfy (inClass " \t")) "whitespace" + _ <- lineEnding "line ending" return atype where message = string "MESSAGE" *> return ArmorMessage @@ -85,7 +82,7 @@ beginLine = do parts = string "MESSAGE, PART " *> (partsdef <|> partsindef) partsdef = do firstnum <- num - word8 (fromIntegral . fromEnum $ '/') + _ <- word8 (fromIntegral . fromEnum $ '/') secondnum <- num return $ ArmorSplitMessage (BL.pack firstnum) (BL.pack secondnum) partsindef = ArmorSplitMessageIndefinite . BL.pack <$> num @@ -100,9 +97,9 @@ armorHeaders = many armorHeader armorHeader :: Parser (String, String) armorHeader = do key <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) - string ": " + _ <- string ": " val <- many1 (satisfy (notInClass "\n\r")) - lineEnding + _ <- lineEnding return (w8sToString key, w8sToString val) where w8sToString = BC8.unpack . B.pack @@ -112,7 +109,7 @@ blankishLine = many (satisfy (inClass " \t")) *> lineEnding endLine :: ArmorType -> Parser ByteString endLine atype = do - string $ "-----END PGP " `B.append` aType atype `B.append` "-----" + _ <- string $ "-----END PGP " `B.append` aType atype `B.append` "-----" lineEnding aType :: ArmorType -> ByteString @@ -140,16 +137,16 @@ base64Data = do base64Line = do b64 <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")) pad <- many (word8 (fromIntegral . fromEnum $ '=')) - lineEnding + _ <- lineEnding let line = B.pack b64 `B.append` B.pack pad case Base64.decode line of Left err -> fail err Right bs -> return bs checksumLine :: Parser ByteString checksumLine = do - word8 (fromIntegral . fromEnum $ '=') + _ <- word8 (fromIntegral . fromEnum $ '=') b64 <- many1 (satisfy (inClass "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")) - lineEnding + _ <- lineEnding let line = B.pack b64 case Base64.decode line of 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 import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL -import qualified Data.ByteString.Char8 as BC8 import qualified Data.ByteString.Lazy.Char8 as BLC8 import qualified Data.ByteString.Base64 as Base64 import Data.Digest.CRC24 (crc24Lazy) -import Data.Serialize (put) import Data.Serialize.Put (runPutLazy, putWord32be) -import Data.String (IsString, fromString) encode :: [Armor] -> B.ByteString 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) import qualified Data.ByteString.Lazy as BL multipartMerge :: [Armor] -> Armor -multipartMerge as = go as (Armor ArmorMessage [] BL.empty) +multipartMerge as' = go as' (Armor ArmorMessage [] BL.empty) where go :: [Armor] -> Armor -> Armor go [] state = state go (Armor at hs bs:as) state = go as (go' at hs bs state) + go _ _ = error "This shouldn't happen." go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs) 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 Other-Modules: Data.Digest.CRC24 , Codec.Encryption.OpenPGP.ASCIIArmor.Multipart , Codec.Encryption.OpenPGP.ASCIIArmor.Utils + Ghc-options: -Wall Build-depends: attoparsec , base > 4 && < 5 , base64-bytestring @@ -47,6 +48,7 @@ Library Test-Suite tests type: exitcode-stdio-1.0 main-is: tests/suite.hs + Ghc-options: -Wall Build-depends: attoparsec , base > 4 && < 5 , 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 @@ -import Test.Framework (defaultMain, testGroup) +import Test.Framework (defaultMain, testGroup, Test) import Test.Framework.Providers.HUnit -import Test.HUnit +import Test.HUnit (Assertion, assertEqual, assertFailure) import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) import Codec.Encryption.OpenPGP.ASCIIArmor.Types @@ -27,6 +27,7 @@ testArmorDecode fp targets = do Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) where getPayload (Armor _ _ pl) = pl + getPayload _ = error "This should not happen." testArmorMultipartDecode :: FilePath -> FilePath -> Assertion testArmorMultipartDecode fp target = do @@ -37,6 +38,7 @@ testArmorMultipartDecode fp target = do Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) where getPayload (Armor _ _ pl) = pl + getPayload _ = error "This should not happen." testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion testClearsignedDecodeBody fp target = do @@ -45,8 +47,10 @@ testClearsignedDecodeBody fp target = do case decodeLazy bs of Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) + _ -> assertFailure "This shouldn't happen." where getBody (ClearSigned _ txt _) = txt + getBody _ = error "This should not happen." convertEndings = crlfUnlinesLazy . BLC8.lines testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion @@ -56,8 +60,10 @@ testClearsignedDecodeSig fp target = do case decodeLazy bs of Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) + _ -> assertFailure "This shouldn't happen." where getSig (ClearSigned _ _ (Armor _ _ sig)) = sig + getSig _ = error "This should not happen." testArmorEncode :: [FilePath] -> FilePath -> Assertion testArmorEncode fps target = do @@ -83,6 +89,7 @@ testStrictEncode fp = do let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)] assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)]) +tests :: [Test] tests = [ testGroup "CRC24" [ testCase "CRC24: A" (testCRC24 (BC8.pack "A") 16680698) @@ -105,4 +112,5 @@ tests = [ ] ] +main :: IO () main = defaultMain tests -- cgit v1.2.3