diff options
Diffstat (limited to 'Codec')
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | 17 | ||||
-rw-r--r-- | Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | 10 |
2 files changed, 14 insertions, 13 deletions
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs index b62ff6a..5d28e46 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Decode.hs | |||
@@ -25,6 +25,7 @@ import qualified Data.ByteString.Char8 as BC8 | |||
25 | import qualified Data.ByteString.Base64 as Base64 | 25 | import qualified Data.ByteString.Base64 as Base64 |
26 | import Data.Digest.CRC24 (crc24) | 26 | import Data.Digest.CRC24 (crc24) |
27 | import Data.Binary.Get (Get, runGetOrFail, getWord8) | 27 | import Data.Binary.Get (Get, runGetOrFail, getWord8) |
28 | import Data.Functor (($>)) | ||
28 | import Data.String (IsString, fromString) | 29 | import Data.String (IsString, fromString) |
29 | import Data.Word (Word32) | 30 | import Data.Word (Word32) |
30 | 31 | ||
@@ -75,10 +76,10 @@ beginLine = do | |||
75 | _ <- lineEnding <?> "line ending" | 76 | _ <- lineEnding <?> "line ending" |
76 | return atype | 77 | return atype |
77 | where | 78 | where |
78 | message = string "MESSAGE" *> return ArmorMessage | 79 | message = string "MESSAGE" $> ArmorMessage |
79 | pubkey = string "PUBLIC KEY BLOCK" *> return ArmorPublicKeyBlock | 80 | pubkey = string "PUBLIC KEY BLOCK" $> ArmorPublicKeyBlock |
80 | privkey = string "PRIVATE KEY BLOCK" *> return ArmorPrivateKeyBlock | 81 | privkey = string "PRIVATE KEY BLOCK" $> ArmorPrivateKeyBlock |
81 | signature = string "SIGNATURE" *> return ArmorSignature | 82 | signature = string "SIGNATURE" $> ArmorSignature |
82 | parts = string "MESSAGE, PART " *> (partsdef <|> partsindef) | 83 | parts = string "MESSAGE, PART " *> (partsdef <|> partsindef) |
83 | partsdef = do | 84 | partsdef = do |
84 | firstnum <- num | 85 | firstnum <- num |
@@ -113,12 +114,12 @@ endLine atype = do | |||
113 | lineEnding | 114 | lineEnding |
114 | 115 | ||
115 | aType :: ArmorType -> B.ByteString | 116 | aType :: ArmorType -> B.ByteString |
116 | aType (ArmorMessage) = BC8.pack "MESSAGE" | 117 | aType ArmorMessage = BC8.pack "MESSAGE" |
117 | aType (ArmorPublicKeyBlock) = BC8.pack "PUBLIC KEY BLOCK" | 118 | aType ArmorPublicKeyBlock = BC8.pack "PUBLIC KEY BLOCK" |
118 | aType (ArmorPrivateKeyBlock) = BC8.pack "PRIVATE KEY BLOCK" | 119 | aType ArmorPrivateKeyBlock = BC8.pack "PRIVATE KEY BLOCK" |
119 | aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` l2s x `B.append` BC8.singleton '/' `B.append` l2s y | 120 | aType (ArmorSplitMessage x y) = BC8.pack "MESSAGE, PART " `B.append` l2s x `B.append` BC8.singleton '/' `B.append` l2s y |
120 | aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` l2s x | 121 | aType (ArmorSplitMessageIndefinite x) = BC8.pack "MESSAGE, PART " `B.append` l2s x |
121 | aType (ArmorSignature) = BC8.pack "SIGNATURE" | 122 | aType ArmorSignature = BC8.pack "SIGNATURE" |
122 | 123 | ||
123 | l2s :: BL.ByteString -> B.ByteString | 124 | l2s :: BL.ByteString -> B.ByteString |
124 | l2s = B.concat . BL.toChunks | 125 | l2s = B.concat . BL.toChunks |
diff --git a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs index fdb9961..cb5b16d 100644 --- a/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs +++ b/Codec/Encryption/OpenPGP/ASCIIArmor/Encode.hs | |||
@@ -37,15 +37,15 @@ endLine :: ArmorType -> ByteString | |||
37 | endLine atype = BLC8.pack "-----END PGP " `BL.append` aType atype `BL.append` BLC8.pack "-----\n" | 37 | endLine atype = BLC8.pack "-----END PGP " `BL.append` aType atype `BL.append` BLC8.pack "-----\n" |
38 | 38 | ||
39 | aType :: ArmorType -> ByteString | 39 | aType :: ArmorType -> ByteString |
40 | aType (ArmorMessage) = BLC8.pack "MESSAGE" | 40 | aType ArmorMessage = BLC8.pack "MESSAGE" |
41 | aType (ArmorPublicKeyBlock) = BLC8.pack "PUBLIC KEY BLOCK" | 41 | aType ArmorPublicKeyBlock = BLC8.pack "PUBLIC KEY BLOCK" |
42 | aType (ArmorPrivateKeyBlock) = BLC8.pack "PRIVATE KEY BLOCK" | 42 | aType ArmorPrivateKeyBlock = BLC8.pack "PRIVATE KEY BLOCK" |
43 | aType (ArmorSplitMessage x y) = BLC8.pack $ "MESSAGE, PART " ++ show x ++ "/" ++ show y | 43 | aType (ArmorSplitMessage x y) = BLC8.pack $ "MESSAGE, PART " ++ show x ++ "/" ++ show y |
44 | aType (ArmorSplitMessageIndefinite x) = BLC8.pack $ "MESSAGE, PART " ++ show x | 44 | aType (ArmorSplitMessageIndefinite x) = BLC8.pack $ "MESSAGE, PART " ++ show x |
45 | aType (ArmorSignature) = BLC8.pack "SIGNATURE" | 45 | aType ArmorSignature = BLC8.pack "SIGNATURE" |
46 | 46 | ||
47 | armorHeaders :: [(String, String)] -> ByteString | 47 | armorHeaders :: [(String, String)] -> ByteString |
48 | armorHeaders ahs = BLC8.unlines . map armorHeader $ ahs | 48 | armorHeaders = BLC8.unlines . map armorHeader |
49 | where | 49 | where |
50 | armorHeader :: (String, String) -> ByteString | 50 | armorHeader :: (String, String) -> ByteString |
51 | armorHeader (k, v) = BLC8.pack k `BL.append` BLC8.pack ": " `BL.append` BLC8.pack v | 51 | armorHeader (k, v) = BLC8.pack k `BL.append` BLC8.pack ": " `BL.append` BLC8.pack v |