summaryrefslogtreecommitdiff
path: root/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs')
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs16
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)
18import Data.Bits (shiftL) 18import Data.Bits (shiftL)
19import Data.ByteString (ByteString) 19import Data.ByteString (ByteString)
20import qualified Data.ByteString as B 20import qualified Data.ByteString as B
21import qualified Data.ByteString.Lazy as BL
21import qualified Data.ByteString.Char8 as BC8 22import qualified Data.ByteString.Char8 as BC8
22import qualified Data.ByteString.Base64 as Base64 23import qualified Data.ByteString.Base64 as Base64
23import Data.Digest.CRC24 (crc24) 24import 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
53armor :: Parser Armor 54armor :: Parser Armor
54armor = do 55armor = 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
62beginLine :: Parser ArmorType 63beginLine :: Parser ArmorType
63beginLine = do 64beginLine = 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
84lineEnding :: Parser ByteString 85lineEnding :: Parser ByteString
@@ -109,10 +110,13 @@ aType :: ArmorType -> ByteString
109aType (ArmorMessage) = BC8.pack "MESSAGE" 110aType (ArmorMessage) = BC8.pack "MESSAGE"
110aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK" 111aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK"
111aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK" 112aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK"
112aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` x `B.append` BC8.singleton '/' `B.append` y 113aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` (l2s x) `B.append` BC8.singleton '/' `B.append` (l2s y)
113aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` x 114aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` (l2s x)
114aType (ArmorSignature) = BC8.pack "SIGNATURE" 115aType (ArmorSignature) = BC8.pack "SIGNATURE"
115 116
117l2s :: BL.ByteString -> ByteString
118l2s = B.concat . BL.toChunks
119
116base64Data :: Parser ByteString 120base64Data :: Parser ByteString
117base64Data = do 121base64Data = do
118 ls <- many1 base64Line 122 ls <- many1 base64Line