diff options
author | Joe Crayne <joe@jerkface.net> | 2019-10-13 04:53:58 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-10-13 04:53:58 -0400 |
commit | 9694b1b6ae3763c44d3b1361b5faa0a7b27e77a9 (patch) | |
tree | 90ca5f2f2d17c808f9a07d5c7ebba346f14c2361 /Codec | |
parent | dae6c79e02d01d0fb6fa0dbf071e69ab62b31ba0 (diff) |
Remove trailing whitespace in the to-hash content.patched
Diffstat (limited to 'Codec')
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs | 16 |
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 | |||
14 | import qualified Data.ByteString.Lazy as BL | 14 | import qualified Data.ByteString.Lazy as BL |
15 | import qualified Data.ByteString.Lazy.Char8 as BLC8 | 15 | import qualified Data.ByteString.Lazy.Char8 as BLC8 |
16 | import Data.List (intersperse) | 16 | import Data.List (intersperse) |
17 | import Data.Char (isSpace) | ||
18 | |||
19 | removeTrailingSpaces :: ByteString -> ByteString | ||
20 | removeTrailingSpaces bs = fst $ BC8.spanEnd isSpace bs | ||
21 | |||
22 | toLast :: (a -> a) -> [a] -> [a] | ||
23 | toLast _ [] = [] | ||
24 | toLast f [x] = [f x] | ||
25 | toLast f (x:xs) = x : toLast f xs | ||
26 | |||
27 | removeTrailingSpacesLazy :: BL.ByteString -> BL.ByteString | ||
28 | removeTrailingSpacesLazy bs = BL.fromChunks $ toLast removeTrailingSpaces $ BL.toChunks bs | ||
17 | 29 | ||
18 | crlfUnlines :: [ByteString] -> ByteString | 30 | crlfUnlines :: [ByteString] -> ByteString |
19 | crlfUnlines [] = B.empty | 31 | crlfUnlines [] = B.empty |
20 | crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") ss | 32 | crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") $ map removeTrailingSpaces ss |
21 | 33 | ||
22 | crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString | 34 | crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString |
23 | crlfUnlinesLazy [] = BL.empty | 35 | crlfUnlinesLazy [] = BL.empty |
24 | crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") ss | 36 | crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") $ map removeTrailingSpacesLazy ss |