summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-12-30 15:22:38 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-12-30 15:22:38 -0500
commit3cb201b180254612a1661301377fa5753cddeb32 (patch)
treecf2a597c875f574bca6aa6efaee0485a2dd34de2
parent55330cc47562d6b5010fcc4ec25175191788a9e4 (diff)
Fix partial packet length support
-rw-r--r--Data/OpenPGP.hs27
1 files changed, 13 insertions, 14 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index 4d049dd..55458b8 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -263,26 +263,25 @@ instance BINARY_CLASS Packet where
263 blen = fromIntegral $ B.length body 263 blen = fromIntegral $ B.length body
264 (body, tag) = put_packet p 264 (body, tag) = put_packet p
265 get = do 265 get = do
266 (t, packet) <- get_packet_bytes 266 tag <- get
267 let (t, l) =
268 if (tag .&. 64) /= 0 then
269 (tag .&. 63, parse_new_length)
270 else
271 ((tag `shiftR` 2) .&. 15, (,) <$> parse_old_length tag <*> pure False)
272 packet <- uncurry get_packet_bytes =<< l
267 localGet (parse_packet t) (B.concat packet) 273 localGet (parse_packet t) (B.concat packet)
268 274
269get_packet_bytes :: Get (Word8, [B.ByteString]) 275get_packet_bytes :: Maybe Word32 -> Bool -> Get [B.ByteString]
270get_packet_bytes = do 276get_packet_bytes len partial = do
271 tag <- get
272 let (t, l) =
273 if (tag .&. 64) /= 0 then
274 (tag .&. 63, fmap (first Just) parse_new_length)
275 else
276 ((tag `shiftR` 2) .&. 15, (,) <$> parse_old_length tag <*> pure False)
277 (len, partial) <- l
278 -- This forces the whole packet to be consumed 277 -- This forces the whole packet to be consumed
279 packet <- maybe getRemainingByteString (getSomeByteString . fromIntegral) len 278 packet <- maybe getRemainingByteString (getSomeByteString . fromIntegral) len
280 if not partial then return (t, [packet]) else 279 if not partial then return [packet] else
281 (,) t <$> ((packet:) . snd) <$> get_packet_bytes 280 (packet:) <$> (uncurry get_packet_bytes =<< parse_new_length)
282 281
283-- http://tools.ietf.org/html/rfc4880#section-4.2.2 282-- http://tools.ietf.org/html/rfc4880#section-4.2.2
284parse_new_length :: Get (Word32, Bool) 283parse_new_length :: Get (Maybe Word32, Bool)
285parse_new_length = do 284parse_new_length = fmap (first Just) $ do
286 len <- fmap fromIntegral (get :: Get Word8) 285 len <- fmap fromIntegral (get :: Get Word8)
287 case len of 286 case len of
288 -- One octet length 287 -- One octet length