From bc63eed255188cb2fecaa9e38e8a9e22a34ccf3b Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 7 Aug 2011 20:12:06 -0500 Subject: putLazyBystring cleaner than mapM putWord8 --- lib/OpenPGP.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/OpenPGP.hs b/lib/OpenPGP.hs index a1e6072..6a161a7 100644 --- a/lib/OpenPGP.hs +++ b/lib/OpenPGP.hs @@ -10,6 +10,7 @@ import qualified Data.ByteString.Lazy.UTF8 as LZ (toString, fromString) import Data.Binary import Data.Binary.Get +import Data.Binary.Put import qualified Codec.Compression.Zlib.Raw as Zip import qualified Codec.Compression.Zlib as Zlib import qualified Codec.Compression.BZip as BZip2 @@ -76,7 +77,7 @@ instance Binary Packet where -- Use 5-octet lengths put (255 :: Word8) put ((fromIntegral $ LZ.length body) :: Word32) - mapM_ putWord8 (LZ.unpack body) + putLazyByteString body where (body, tag) = put_packet p get = do tag <- get :: Get Word8 @@ -410,7 +411,7 @@ instance Binary MPI where put (((fromIntegral . LZ.length $ bytes) - 1) * 8 + floor (logBase 2 $ fromIntegral (bytes `LZ.index` 0)) + 1 :: Word16) - mapM_ putWord8 (LZ.unpack bytes) + putLazyByteString bytes where bytes = LZ.unfoldr (\x -> if x == 0 then Nothing else Just (fromIntegral x, x `shiftR` 8)) i get = do @@ -430,7 +431,7 @@ instance Binary SignatureSubpacket where put (255 :: Word8) put ((fromIntegral $ LZ.length body) + 1 :: Word32) put tag - mapM_ putWord8 (LZ.unpack body) + putLazyByteString body where (body, tag) = put_signature_subpacket p get = do len <- fmap fromIntegral (get :: Get Word8) -- cgit v1.2.3