From 1ddca48c27cece9352e85ce6188f697eb9124750 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Thu, 26 Apr 2012 19:34:16 -0400 Subject: Introduce some lazy bytestrings internally. --- Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs') diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs index b0033a8..b89fbfa 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs @@ -18,6 +18,7 @@ import Data.Attoparsec.Combinator (manyTill) import Data.Bits (shiftL) import Data.ByteString (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.Base64 as Base64 import Data.Digest.CRC24 (crc24) @@ -48,7 +49,7 @@ clearsigned = do blankishLine "blank line" cleartext <- dashEscapedCleartext sig <- armor - return $ ClearSigned headers cleartext sig + return $ ClearSigned headers (BL.fromChunks [cleartext]) sig armor :: Parser Armor armor = do @@ -57,7 +58,7 @@ armor = do blankishLine "blank line" payload <- base64Data "base64 data" endLine atype "end line" - return $ Armor atype headers payload + return $ Armor atype headers (BL.fromChunks [payload]) beginLine :: Parser ArmorType beginLine = do @@ -77,8 +78,8 @@ beginLine = do firstnum <- num word8 (fromIntegral . fromEnum $ '/') secondnum <- num - return $ ArmorSplitMessage (B.pack firstnum) (B.pack secondnum) - partsindef = ArmorSplitMessageIndefinite . B.pack <$> num + return $ ArmorSplitMessage (BL.pack firstnum) (BL.pack secondnum) + partsindef = ArmorSplitMessageIndefinite . BL.pack <$> num num = many1 (satisfy isDigit_w8) "number" lineEnding :: Parser ByteString @@ -109,10 +110,13 @@ aType :: ArmorType -> ByteString aType (ArmorMessage) = BC8.pack "MESSAGE" aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK" aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK" -aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` x `B.append` BC8.singleton '/' `B.append` y -aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` x +aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` (l2s x) `B.append` BC8.singleton '/' `B.append` (l2s y) +aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` (l2s x) aType (ArmorSignature) = BC8.pack "SIGNATURE" +l2s :: BL.ByteString -> ByteString +l2s = B.concat . BL.toChunks + base64Data :: Parser ByteString base64Data = do ls <- many1 base64Line -- cgit v1.2.3