summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2013-01-05 11:07:21 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2013-01-05 11:07:21 -0500
commit9a7ae71134ec96fcf1485d4564a8ce55c8c9aff8 (patch)
tree7ca96febbfada6a7621008214136a0ba4b4bbe02
parent7c12294d30276113d59b90bc751d6047ffd677f1 (diff)
Fix the cereal version so that it works
-rw-r--r--Data/OpenPGP.hs16
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
79import qualified Data.ByteString.Lazy as LZ 79import qualified Data.ByteString.Lazy as LZ
80 80
81#ifdef CEREAL 81#ifdef CEREAL
82import Data.Serialize 82import Data.Serialize hiding (decode)
83import qualified Data.ByteString as B 83import qualified Data.ByteString as B
84import qualified Data.ByteString.UTF8 as B (toString, fromString) 84import qualified Data.ByteString.UTF8 as B (toString, fromString)
85#define BINARY_CLASS Serialize 85#define BINARY_CLASS Serialize
86#else 86#else
87import Data.Binary 87import Data.Binary hiding (decode)
88import Data.Binary.Get 88import Data.Binary.Get
89import Data.Binary.Put 89import Data.Binary.Put
90import qualified Data.ByteString.Lazy as B 90import qualified Data.ByteString.Lazy as B
@@ -122,6 +122,9 @@ toStrictBS = B.concat . LZ.toChunks
122 122
123toLazyBS :: B.ByteString -> LZ.ByteString 123toLazyBS :: B.ByteString -> LZ.ByteString
124toLazyBS = LZ.fromChunks . (:[]) 124toLazyBS = LZ.fromChunks . (:[])
125
126lazyEncode :: (Serialize a) => a -> LZ.ByteString
127lazyEncode = toLazyBS . encode
125#else 128#else
126getRemainingByteString :: Get B.ByteString 129getRemainingByteString :: Get B.ByteString
127getRemainingByteString = getRemainingLazyByteString 130getRemainingByteString = getRemainingLazyByteString
@@ -144,6 +147,9 @@ compress = lazyCompress
144 147
145decompress :: CompressionAlgorithm -> B.ByteString -> B.ByteString 148decompress :: CompressionAlgorithm -> B.ByteString -> B.ByteString
146decompress = lazyDecompress 149decompress = lazyDecompress
150
151lazyEncode :: (Binary a) => a -> LZ.ByteString
152lazyEncode = encode
147#endif 153#endif
148 154
149lazyCompress :: CompressionAlgorithm -> LZ.ByteString -> LZ.ByteString 155lazyCompress :: 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
749string2key :: (HashAlgorithm -> LZ.ByteString -> BS.ByteString) -> S2K -> LZ.ByteString -> LZ.ByteString 755string2key :: (HashAlgorithm -> LZ.ByteString -> BS.ByteString) -> S2K -> LZ.ByteString -> LZ.ByteString
750string2key hsh (SimpleS2K halgo) s = infiniHashes (hsh halgo) s 756string2key hsh (SimpleS2K halgo) s = infiniHashes (hsh halgo) s
751string2key hsh (SaltedS2K halgo salt) s = 757string2key hsh (SaltedS2K halgo salt) s =
752 infiniHashes (hsh halgo) (encode salt `LZ.append` s) 758 infiniHashes (hsh halgo) (lazyEncode salt `LZ.append` s)
753string2key hsh (IteratedSaltedS2K halgo salt count) s = 759string2key 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)
757string2key _ s2k _ = error $ "Unsupported S2K specifier: " ++ show s2k 763string2key _ s2k _ = error $ "Unsupported S2K specifier: " ++ show s2k
758 764
759infiniHashes :: (LZ.ByteString -> BS.ByteString) -> LZ.ByteString -> LZ.ByteString 765infiniHashes :: (LZ.ByteString -> BS.ByteString) -> LZ.ByteString -> LZ.ByteString