summaryrefslogtreecommitdiff
path: root/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs')
-rw-r--r--Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
index 28bb3e6..00d9dd3 100644
--- a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
+++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs
@@ -22,6 +22,7 @@ encode = B.concat . map armor
22 22
23armor :: Armor -> ByteString 23armor :: Armor -> ByteString
24armor (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 24armor (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
25armor (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
25 26
26blankLine :: ByteString 27blankLine :: ByteString
27blankLine = BC8.singleton '\n' 28blankLine = BC8.singleton '\n'
@@ -57,3 +58,12 @@ wordWrap lw bs
57 58
58armorChecksum :: ByteString -> ByteString 59armorChecksum :: ByteString -> ByteString
59armorChecksum = BC8.cons '=' . armorData . B.tail . runPut . putWord32be . crc24 60armorChecksum = BC8.cons '=' . armorData . B.tail . runPut . putWord32be . crc24
61
62dashEscape :: ByteString -> ByteString
63dashEscape = BC8.unlines . map escapeLine . BC8.lines
64 where
65 escapeLine :: ByteString -> ByteString
66 escapeLine l
67 | BC8.singleton '-' `B.isPrefixOf` l = BC8.pack "- " `B.append` l
68 | BC8.pack "From " `B.isPrefixOf` l = BC8.pack "- " `B.append` l
69 | otherwise = l