summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-10-13 04:53:58 -0400
committerJoe Crayne <joe@jerkface.net>2019-10-13 04:53:58 -0400
commit9694b1b6ae3763c44d3b1361b5faa0a7b27e77a9 (patch)
tree90ca5f2f2d17c808f9a07d5c7ebba346f14c2361
parentdae6c79e02d01d0fb6fa0dbf071e69ab62b31ba0 (diff)
Remove trailing whitespace in the to-hash content.patched
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
index f1068fe..e36b8db 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs
@@ -14,11 +14,23 @@ import qualified Data.ByteString.Char8 as BC8
14import qualified Data.ByteString.Lazy as BL 14import qualified Data.ByteString.Lazy as BL
15import qualified Data.ByteString.Lazy.Char8 as BLC8 15import qualified Data.ByteString.Lazy.Char8 as BLC8
16import Data.List (intersperse) 16import Data.List (intersperse)
17import Data.Char (isSpace)
18
19removeTrailingSpaces :: ByteString -> ByteString
20removeTrailingSpaces bs = fst $ BC8.spanEnd isSpace bs
21
22toLast :: (a -> a) -> [a] -> [a]
23toLast _ [] = []
24toLast f [x] = [f x]
25toLast f (x:xs) = x : toLast f xs
26
27removeTrailingSpacesLazy :: BL.ByteString -> BL.ByteString
28removeTrailingSpacesLazy bs = BL.fromChunks $ toLast removeTrailingSpaces $ BL.toChunks bs
17 29
18crlfUnlines :: [ByteString] -> ByteString 30crlfUnlines :: [ByteString] -> ByteString
19crlfUnlines [] = B.empty 31crlfUnlines [] = B.empty
20crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") ss 32crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") $ map removeTrailingSpaces ss
21 33
22crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString 34crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString
23crlfUnlinesLazy [] = BL.empty 35crlfUnlinesLazy [] = BL.empty
24crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") ss 36crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") $ map removeTrailingSpacesLazy ss