diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2013-01-05 11:07:21 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2013-01-05 11:07:21 -0500 |
commit | 9a7ae71134ec96fcf1485d4564a8ce55c8c9aff8 (patch) | |
tree | 7ca96febbfada6a7621008214136a0ba4b4bbe02 /Data | |
parent | 7c12294d30276113d59b90bc751d6047ffd677f1 (diff) |
Fix the cereal version so that it works
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index 1108aa8..459925e 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -79,12 +79,12 @@ import qualified Data.ByteString as BS | |||
79 | import qualified Data.ByteString.Lazy as LZ | 79 | import qualified Data.ByteString.Lazy as LZ |
80 | 80 | ||
81 | #ifdef CEREAL | 81 | #ifdef CEREAL |
82 | import Data.Serialize | 82 | import Data.Serialize hiding (decode) |
83 | import qualified Data.ByteString as B | 83 | import qualified Data.ByteString as B |
84 | import qualified Data.ByteString.UTF8 as B (toString, fromString) | 84 | import qualified Data.ByteString.UTF8 as B (toString, fromString) |
85 | #define BINARY_CLASS Serialize | 85 | #define BINARY_CLASS Serialize |
86 | #else | 86 | #else |
87 | import Data.Binary | 87 | import Data.Binary hiding (decode) |
88 | import Data.Binary.Get | 88 | import Data.Binary.Get |
89 | import Data.Binary.Put | 89 | import Data.Binary.Put |
90 | import qualified Data.ByteString.Lazy as B | 90 | import qualified Data.ByteString.Lazy as B |
@@ -122,6 +122,9 @@ toStrictBS = B.concat . LZ.toChunks | |||
122 | 122 | ||
123 | toLazyBS :: B.ByteString -> LZ.ByteString | 123 | toLazyBS :: B.ByteString -> LZ.ByteString |
124 | toLazyBS = LZ.fromChunks . (:[]) | 124 | toLazyBS = LZ.fromChunks . (:[]) |
125 | |||
126 | lazyEncode :: (Serialize a) => a -> LZ.ByteString | ||
127 | lazyEncode = toLazyBS . encode | ||
125 | #else | 128 | #else |
126 | getRemainingByteString :: Get B.ByteString | 129 | getRemainingByteString :: Get B.ByteString |
127 | getRemainingByteString = getRemainingLazyByteString | 130 | getRemainingByteString = getRemainingLazyByteString |
@@ -144,6 +147,9 @@ compress = lazyCompress | |||
144 | 147 | ||
145 | decompress :: CompressionAlgorithm -> B.ByteString -> B.ByteString | 148 | decompress :: CompressionAlgorithm -> B.ByteString -> B.ByteString |
146 | decompress = lazyDecompress | 149 | decompress = lazyDecompress |
150 | |||
151 | lazyEncode :: (Binary a) => a -> LZ.ByteString | ||
152 | lazyEncode = encode | ||
147 | #endif | 153 | #endif |
148 | 154 | ||
149 | lazyCompress :: CompressionAlgorithm -> LZ.ByteString -> LZ.ByteString | 155 | lazyCompress :: CompressionAlgorithm -> LZ.ByteString -> LZ.ByteString |
@@ -604,7 +610,7 @@ parse_packet 5 = do | |||
604 | _ | s2k_useage `elem` [255, 254] -> (,) <$> get <*> get | 610 | _ | s2k_useage `elem` [255, 254] -> (,) <$> get <*> get |
605 | _ | s2k_useage > 0 -> | 611 | _ | s2k_useage > 0 -> |
606 | -- s2k_useage is symmetric_type in this case | 612 | -- s2k_useage is symmetric_type in this case |
607 | return (decode $ encode s2k_useage, SimpleS2K MD5) | 613 | (,) <$> localGet get (encode s2k_useage) <*> pure (SimpleS2K MD5) |
608 | _ -> | 614 | _ -> |
609 | return (Unencrypted, S2K 100 B.empty) | 615 | return (Unencrypted, S2K 100 B.empty) |
610 | if symmetric_algorithm /= Unencrypted then do { | 616 | if symmetric_algorithm /= Unencrypted then do { |
@@ -749,11 +755,11 @@ instance BINARY_CLASS S2K where | |||
749 | string2key :: (HashAlgorithm -> LZ.ByteString -> BS.ByteString) -> S2K -> LZ.ByteString -> LZ.ByteString | 755 | string2key :: (HashAlgorithm -> LZ.ByteString -> BS.ByteString) -> S2K -> LZ.ByteString -> LZ.ByteString |
750 | string2key hsh (SimpleS2K halgo) s = infiniHashes (hsh halgo) s | 756 | string2key hsh (SimpleS2K halgo) s = infiniHashes (hsh halgo) s |
751 | string2key hsh (SaltedS2K halgo salt) s = | 757 | string2key hsh (SaltedS2K halgo salt) s = |
752 | infiniHashes (hsh halgo) (encode salt `LZ.append` s) | 758 | infiniHashes (hsh halgo) (lazyEncode salt `LZ.append` s) |
753 | string2key hsh (IteratedSaltedS2K halgo salt count) s = | 759 | string2key hsh (IteratedSaltedS2K halgo salt count) s = |
754 | infiniHashes (hsh halgo) $ | 760 | infiniHashes (hsh halgo) $ |
755 | LZ.take (max (fromIntegral count) (LZ.length s)) | 761 | LZ.take (max (fromIntegral count) (LZ.length s)) |
756 | (LZ.cycle $ encode salt `LZ.append` s) | 762 | (LZ.cycle $ lazyEncode salt `LZ.append` s) |
757 | string2key _ s2k _ = error $ "Unsupported S2K specifier: " ++ show s2k | 763 | string2key _ s2k _ = error $ "Unsupported S2K specifier: " ++ show s2k |
758 | 764 | ||
759 | infiniHashes :: (LZ.ByteString -> BS.ByteString) -> LZ.ByteString -> LZ.ByteString | 765 | infiniHashes :: (LZ.ByteString -> BS.ByteString) -> LZ.ByteString -> LZ.ByteString |