summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClint Adams <clint@debian.org>2018-03-28 22:48:44 -0400
committerClint Adams <clint@debian.org>2018-03-28 22:48:44 -0400
commit8017336edbbfb4ab52ac3ab2309c286842e8f6a2 (patch)
treea32612a82b625d9d873f75e8d83c7b6279d62f26
parent5fe2d10c984dcfcdff01c7d73ab8e8bf95d27b26 (diff)
Clean up hlint warnings
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs17
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs10
-rw-r--r--tests/suite.hs8
3 files changed, 18 insertions, 17 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
index b62ff6a..5d28e46 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
@@ -25,6 +25,7 @@ import qualified Data.ByteString.Char8 as BC8
25import qualified Data.ByteString.Base64 as Base64 25import qualified Data.ByteString.Base64 as Base64
26import Data.Digest.CRC24 (crc24) 26import Data.Digest.CRC24 (crc24)
27import Data.Binary.Get (Get, runGetOrFail, getWord8) 27import Data.Binary.Get (Get, runGetOrFail, getWord8)
28import Data.Functor (($>))
28import Data.String (IsString, fromString) 29import Data.String (IsString, fromString)
29import Data.Word (Word32) 30import Data.Word (Word32)
30 31
@@ -75,10 +76,10 @@ beginLine = do
75 _ <- lineEnding <?> "line ending" 76 _ <- lineEnding <?> "line ending"
76 return atype 77 return atype
77 where 78 where
78 message = string "MESSAGE" *> return ArmorMessage 79 message = string "MESSAGE" $> ArmorMessage
79 pubkey = string "PUBLIC KEY BLOCK" *> return ArmorPublicKeyBlock 80 pubkey = string "PUBLIC KEY BLOCK" $> ArmorPublicKeyBlock
80 privkey = string "PRIVATE KEY BLOCK" *> return ArmorPrivateKeyBlock 81 privkey = string "PRIVATE KEY BLOCK" $> ArmorPrivateKeyBlock
81 signature = string "SIGNATURE" *> return ArmorSignature 82 signature = string "SIGNATURE" $> ArmorSignature
82 parts = string "MESSAGE, PART " *> (partsdef <|> partsindef) 83 parts = string "MESSAGE, PART " *> (partsdef <|> partsindef)
83 partsdef = do 84 partsdef = do
84 firstnum <- num 85 firstnum <- num
@@ -113,12 +114,12 @@ endLine atype = do
113 lineEnding 114 lineEnding
114 115
115aType :: ArmorType -> B.ByteString 116aType :: ArmorType -> B.ByteString
116aType (ArmorMessage) = BC8.pack "MESSAGE" 117aType ArmorMessage = BC8.pack "MESSAGE"
117aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK" 118aType ArmorPublicKeyBlock = BC8.pack "PUBLIC KEY BLOCK"
118aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK" 119aType ArmorPrivateKeyBlock = BC8.pack "PRIVATE KEY BLOCK"
119aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` l2s x `B.append` BC8.singleton '/' `B.append` l2s y 120aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` l2s x `B.append` BC8.singleton '/' `B.append` l2s y
120aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` l2s x 121aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` l2s x
121aType (ArmorSignature) = BC8.pack "SIGNATURE" 122aType ArmorSignature = BC8.pack "SIGNATURE"
122 123
123l2s :: BL.ByteString -> B.ByteString 124l2s :: BL.ByteString -> B.ByteString
124l2s = B.concat . BL.toChunks 125l2s = B.concat . BL.toChunks
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
index fdb9961..cb5b16d 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
@@ -37,15 +37,15 @@ endLine :: ArmorType -> ByteString
37endLine atype = BLC8.pack "-----END PGP " `BL.append` aType atype `BL.append` BLC8.pack "-----\n" 37endLine atype = BLC8.pack "-----END PGP " `BL.append` aType atype `BL.append` BLC8.pack "-----\n"
38 38
39aType :: ArmorType -> ByteString 39aType :: ArmorType -> ByteString
40aType (ArmorMessage) = BLC8.pack "MESSAGE" 40aType ArmorMessage = BLC8.pack "MESSAGE"
41aType (ArmorPublicKeyBlock) = BLC8.pack "PUBLIC KEY BLOCK" 41aType ArmorPublicKeyBlock = BLC8.pack "PUBLIC KEY BLOCK"
42aType (ArmorPrivateKeyBlock) = BLC8.pack "PRIVATE KEY BLOCK" 42aType ArmorPrivateKeyBlock = BLC8.pack "PRIVATE KEY BLOCK"
43aType (ArmorSplitMessage x y) = BLC8.pack $ "MESSAGE, PART " ++ show x ++ "/" ++ show y 43aType (ArmorSplitMessage x y) = BLC8.pack $ "MESSAGE, PART " ++ show x ++ "/" ++ show y
44aType (ArmorSplitMessageIndefinite x) = BLC8.pack $ "MESSAGE, PART " ++ show x 44aType (ArmorSplitMessageIndefinite x) = BLC8.pack $ "MESSAGE, PART " ++ show x
45aType (ArmorSignature) = BLC8.pack "SIGNATURE" 45aType ArmorSignature = BLC8.pack "SIGNATURE"
46 46
47armorHeaders :: [(String, String)] -> ByteString 47armorHeaders :: [(String, String)] -> ByteString
48armorHeaders ahs = BLC8.unlines . map armorHeader $ ahs 48armorHeaders = BLC8.unlines . map armorHeader
49 where 49 where
50 armorHeader :: (String, String) -> ByteString 50 armorHeader :: (String, String) -> ByteString
51 armorHeader (k, v) = BLC8.pack k `BL.append` BLC8.pack ": " `BL.append` BLC8.pack v 51 armorHeader (k, v) = BLC8.pack k `BL.append` BLC8.pack ": " `BL.append` BLC8.pack v
diff --git a/tests/suite.hs b/tests/suite.hs
index 3a7b7eb..a8b5a30 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -67,25 +67,25 @@ testArmorEncode :: [FilePath] -> FilePath -> Assertion
67testArmorEncode fps target = do 67testArmorEncode fps target = do
68 bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps 68 bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps
69 tbs <- BL.readFile $ "tests/data/" ++ target 69 tbs <- BL.readFile $ "tests/data/" ++ target
70 assertEqual ("literaldata") tbs (encodeLazy (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) 70 assertEqual "literaldata" tbs (encodeLazy (map (Armor ArmorMessage [("Version","OpenPrivacy 0.99")]) bss))
71 71
72testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion 72testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion
73testClearsignedEncode ftxt fsig ftarget = do 73testClearsignedEncode ftxt fsig ftarget = do
74 txt <- BL.readFile $ "tests/data/" ++ ftxt 74 txt <- BL.readFile $ "tests/data/" ++ ftxt
75 sig <- BL.readFile $ "tests/data/" ++ fsig 75 sig <- BL.readFile $ "tests/data/" ++ fsig
76 target <- BL.readFile $ "tests/data/" ++ ftarget 76 target <- BL.readFile $ "tests/data/" ++ ftarget
77 assertEqual ("clearsigned encode") target (encodeLazy [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)]) 77 assertEqual "clearsigned encode" target (encodeLazy [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)])
78 78
79testStrictDecode :: FilePath -> Assertion 79testStrictDecode :: FilePath -> Assertion
80testStrictDecode fp = do 80testStrictDecode fp = do
81 bs <- BL.readFile $ "tests/data/" ++ fp 81 bs <- BL.readFile $ "tests/data/" ++ fp
82 assertEqual ("strict decode") (decodeLazy bs :: Either String [Armor]) (decode (B.concat . BL.toChunks $ bs) :: Either String [Armor]) 82 assertEqual "strict decode" (decodeLazy bs :: Either String [Armor]) (decode (B.concat . BL.toChunks $ bs) :: Either String [Armor])
83 83
84testStrictEncode :: FilePath -> Assertion 84testStrictEncode :: FilePath -> Assertion
85testStrictEncode fp = do 85testStrictEncode fp = do
86 bs <- BL.readFile $ "tests/data/" ++ fp 86 bs <- BL.readFile $ "tests/data/" ++ fp
87 let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)] 87 let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)]
88 assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)]) 88 assertEqual "strict encode" (encodeLazy fakearmors) (BL.fromChunks [encode fakearmors])
89 89
90tests :: TestTree 90tests :: TestTree
91tests = testGroup "openpgp-asciiarmor" [ 91tests = testGroup "openpgp-asciiarmor" [