diff options
Diffstat (limited to 'Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs')
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | 10 |
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 | ||
23 | armor :: Armor -> ByteString | 23 | 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 | 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 (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 | ||
26 | blankLine :: ByteString | 27 | blankLine :: ByteString |
27 | blankLine = BC8.singleton '\n' | 28 | blankLine = BC8.singleton '\n' |
@@ -57,3 +58,12 @@ wordWrap lw bs | |||
57 | 58 | ||
58 | armorChecksum :: ByteString -> ByteString | 59 | armorChecksum :: ByteString -> ByteString |
59 | armorChecksum = BC8.cons '=' . armorData . B.tail . runPut . putWord32be . crc24 | 60 | armorChecksum = BC8.cons '=' . armorData . B.tail . runPut . putWord32be . crc24 |
61 | |||
62 | dashEscape :: ByteString -> ByteString | ||
63 | dashEscape = 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 | ||