diff options
author | Clint Adams <clint@debian.org> | 2012-04-26 19:34:16 -0400 |
---|---|---|
committer | Clint Adams <clint@debian.org> | 2012-04-26 19:34:16 -0400 |
commit | 1ddca48c27cece9352e85ce6188f697eb9124750 (patch) | |
tree | 2fd164848c8ba34180c27a843cb69ab720469c24 /Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | |
parent | 716dd382221343e5da5daf1a9a8ac40304a7d74b (diff) |
Introduce some lazy bytestrings internally.
Diffstat (limited to 'Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs')
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | 16 |
1 files changed, 10 insertions, 6 deletions
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) | |||
18 | import Data.Bits (shiftL) | 18 | import Data.Bits (shiftL) |
19 | import Data.ByteString (ByteString) | 19 | import Data.ByteString (ByteString) |
20 | import qualified Data.ByteString as B | 20 | import qualified Data.ByteString as B |
21 | import qualified Data.ByteString.Lazy as BL | ||
21 | import qualified Data.ByteString.Char8 as BC8 | 22 | import qualified Data.ByteString.Char8 as BC8 |
22 | import qualified Data.ByteString.Base64 as Base64 | 23 | import qualified Data.ByteString.Base64 as Base64 |
23 | import Data.Digest.CRC24 (crc24) | 24 | import Data.Digest.CRC24 (crc24) |
@@ -48,7 +49,7 @@ clearsigned = do | |||
48 | blankishLine <?> "blank line" | 49 | blankishLine <?> "blank line" |
49 | cleartext <- dashEscapedCleartext | 50 | cleartext <- dashEscapedCleartext |
50 | sig <- armor | 51 | sig <- armor |
51 | return $ ClearSigned headers cleartext sig | 52 | return $ ClearSigned headers (BL.fromChunks [cleartext]) sig |
52 | 53 | ||
53 | armor :: Parser Armor | 54 | armor :: Parser Armor |
54 | armor = do | 55 | armor = do |
@@ -57,7 +58,7 @@ armor = do | |||
57 | blankishLine <?> "blank line" | 58 | blankishLine <?> "blank line" |
58 | payload <- base64Data <?> "base64 data" | 59 | payload <- base64Data <?> "base64 data" |
59 | endLine atype <?> "end line" | 60 | endLine atype <?> "end line" |
60 | return $ Armor atype headers payload | 61 | return $ Armor atype headers (BL.fromChunks [payload]) |
61 | 62 | ||
62 | beginLine :: Parser ArmorType | 63 | beginLine :: Parser ArmorType |
63 | beginLine = do | 64 | beginLine = do |
@@ -77,8 +78,8 @@ beginLine = do | |||
77 | firstnum <- num | 78 | firstnum <- num |
78 | word8 (fromIntegral . fromEnum $ '/') | 79 | word8 (fromIntegral . fromEnum $ '/') |
79 | secondnum <- num | 80 | secondnum <- num |
80 | return $ ArmorSplitMessage (B.pack firstnum) (B.pack secondnum) | 81 | return $ ArmorSplitMessage (BL.pack firstnum) (BL.pack secondnum) |
81 | partsindef = ArmorSplitMessageIndefinite . B.pack <$> num | 82 | partsindef = ArmorSplitMessageIndefinite . BL.pack <$> num |
82 | num = many1 (satisfy isDigit_w8) <?> "number" | 83 | num = many1 (satisfy isDigit_w8) <?> "number" |
83 | 84 | ||
84 | lineEnding :: Parser ByteString | 85 | lineEnding :: Parser ByteString |
@@ -109,10 +110,13 @@ aType :: ArmorType -> ByteString | |||
109 | aType (ArmorMessage) = BC8.pack "MESSAGE" | 110 | aType (ArmorMessage) = BC8.pack "MESSAGE" |
110 | aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK" | 111 | aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK" |
111 | aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK" | 112 | aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK" |
112 | aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` x `B.append` BC8.singleton '/' `B.append` y | 113 | aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` (l2s x) `B.append` BC8.singleton '/' `B.append` (l2s y) |
113 | aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` x | 114 | aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` (l2s x) |
114 | aType (ArmorSignature) = BC8.pack "SIGNATURE" | 115 | aType (ArmorSignature) = BC8.pack "SIGNATURE" |
115 | 116 | ||
117 | l2s :: BL.ByteString -> ByteString | ||
118 | l2s = B.concat . BL.toChunks | ||
119 | |||
116 | base64Data :: Parser ByteString | 120 | base64Data :: Parser ByteString |
117 | base64Data = do | 121 | base64Data = do |
118 | ls <- many1 base64Line | 122 | ls <- many1 base64Line |