diff options
Diffstat (limited to 'Codec/Encryption')
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | 16 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | 5 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs | 10 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Types.hs | 2 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs | 7 |
5 files changed, 26 insertions, 14 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 |
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs index 00d9dd3..06d7f1a 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | |||
@@ -10,6 +10,7 @@ module Codec.Encryption.OpenPGP.ASCIIArmor.Encode ( | |||
10 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 10 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
11 | import Data.ByteString (ByteString) | 11 | import Data.ByteString (ByteString) |
12 | import qualified Data.ByteString as B | 12 | import qualified Data.ByteString as B |
13 | import qualified Data.ByteString.Lazy as BL | ||
13 | import qualified Data.ByteString.Char8 as BC8 | 14 | import qualified Data.ByteString.Char8 as BC8 |
14 | import qualified Data.ByteString.Base64 as Base64 | 15 | import qualified Data.ByteString.Base64 as Base64 |
15 | import Data.Digest.CRC24 (crc24) | 16 | import Data.Digest.CRC24 (crc24) |
@@ -21,8 +22,8 @@ encode :: [Armor] -> ByteString | |||
21 | encode = B.concat . map armor | 22 | encode = B.concat . map armor |
22 | 23 | ||
23 | armor :: Armor -> ByteString | 24 | armor :: Armor -> ByteString |
24 | armor (Armor atype ahs bs) = beginLine atype `B.append` armorHeaders ahs `B.append` blankLine `B.append` armorData bs `B.append` armorChecksum bs `B.append` endLine atype | 25 | armor (Armor atype ahs bs) = beginLine atype `B.append` armorHeaders ahs `B.append` blankLine `B.append` armorData (B.concat . BL.toChunks $ bs) `B.append` armorChecksum (B.concat . BL.toChunks $ bs) `B.append` endLine atype |
25 | armor (ClearSigned chs ctxt csig) = BC8.pack "-----BEGIN PGP SIGNED MESSAGE-----\n" `B.append` armorHeaders chs `B.append` blankLine `B.append` dashEscape ctxt `B.append` armor csig | 26 | armor (ClearSigned chs ctxt csig) = BC8.pack "-----BEGIN PGP SIGNED MESSAGE-----\n" `B.append` armorHeaders chs `B.append` blankLine `B.append` dashEscape (B.concat . BL.toChunks $ ctxt) `B.append` armor csig |
26 | 27 | ||
27 | blankLine :: ByteString | 28 | blankLine :: ByteString |
28 | blankLine = BC8.singleton '\n' | 29 | blankLine = BC8.singleton '\n' |
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs index 8719c7c..313c3bc 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Multipart.hs | |||
@@ -9,16 +9,16 @@ module Codec.Encryption.OpenPGP.ASCIIArmor.Multipart ( | |||
9 | 9 | ||
10 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 10 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
11 | 11 | ||
12 | import Data.ByteString (ByteString) | 12 | import Data.ByteString.Lazy (ByteString) |
13 | import qualified Data.ByteString as B | 13 | import qualified Data.ByteString.Lazy as BL |
14 | 14 | ||
15 | multipartMerge :: [Armor] -> Armor | 15 | multipartMerge :: [Armor] -> Armor |
16 | multipartMerge as = go as (Armor ArmorMessage [] B.empty) | 16 | multipartMerge as = go as (Armor ArmorMessage [] BL.empty) |
17 | where | 17 | where |
18 | go :: [Armor] -> Armor -> Armor | 18 | go :: [Armor] -> Armor -> Armor |
19 | go [] state = state | 19 | go [] state = state |
20 | go ((Armor at hs bs):as) state = go as (go' at hs bs state) | 20 | go ((Armor at hs bs):as) state = go as (go' at hs bs state) |
21 | go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor | 21 | go' :: ArmorType -> [(String,String)] -> ByteString -> Armor -> Armor |
22 | go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `B.append` bs) | 22 | go' (ArmorSplitMessage _ _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs) |
23 | go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `B.append` bs) | 23 | go' (ArmorSplitMessageIndefinite _) hs bs (Armor _ ohs obs) = Armor ArmorMessage (ohs ++ hs) (obs `BL.append` bs) |
24 | go' _ _ _ state = state | 24 | go' _ _ _ state = state |
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Types.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Types.hs index 88a03ce..fa83d23 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Types.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Types.hs | |||
@@ -8,7 +8,7 @@ module Codec.Encryption.OpenPGP.ASCIIArmor.Types ( | |||
8 | , ArmorType(..) | 8 | , ArmorType(..) |
9 | ) where | 9 | ) where |
10 | 10 | ||
11 | import Data.ByteString (ByteString) | 11 | import Data.ByteString.Lazy (ByteString) |
12 | 12 | ||
13 | data Armor = Armor ArmorType [(String, String)] ByteString | 13 | data Armor = Armor ArmorType [(String, String)] ByteString |
14 | | ClearSigned [(String, String)] ByteString Armor | 14 | | ClearSigned [(String, String)] ByteString Armor |
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs index 014c8aa..dddecab 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Utils.hs | |||
@@ -5,13 +5,20 @@ | |||
5 | 5 | ||
6 | module Codec.Encryption.OpenPGP.ASCIIArmor.Utils ( | 6 | module Codec.Encryption.OpenPGP.ASCIIArmor.Utils ( |
7 | crlfUnlines | 7 | crlfUnlines |
8 | , crlfUnlinesLazy | ||
8 | ) where | 9 | ) where |
9 | 10 | ||
10 | import Data.ByteString (ByteString) | 11 | import Data.ByteString (ByteString) |
11 | import qualified Data.ByteString as B | 12 | import qualified Data.ByteString as B |
12 | import qualified Data.ByteString.Char8 as BC8 | 13 | import qualified Data.ByteString.Char8 as BC8 |
14 | import qualified Data.ByteString.Lazy as BL | ||
15 | import qualified Data.ByteString.Lazy.Char8 as BLC8 | ||
13 | import Data.List (intersperse) | 16 | import Data.List (intersperse) |
14 | 17 | ||
15 | crlfUnlines :: [ByteString] -> ByteString | 18 | crlfUnlines :: [ByteString] -> ByteString |
16 | crlfUnlines [] = B.empty | 19 | crlfUnlines [] = B.empty |
17 | crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") ss | 20 | crlfUnlines ss = B.concat $ intersperse (BC8.pack "\r\n") ss |
21 | |||
22 | crlfUnlinesLazy :: [BL.ByteString] -> BL.ByteString | ||
23 | crlfUnlinesLazy [] = BL.empty | ||
24 | crlfUnlinesLazy ss = BL.concat $ intersperse (BLC8.pack "\r\n") ss | ||