diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-24 17:50:08 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-24 17:50:08 -0500 |
commit | 4df371631b16d753dd262171ec82c3ebaea42a10 (patch) | |
tree | aaeb82a909ded1a588bc9507d2b72e5cdc8b0a8c /Data | |
parent | a47e1ba41aef9276d7654e602fd7445cad0e1355 (diff) |
Represent unsupported packets and subpackets by their literal bytes
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP.hs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index bab48a4..be50d1a 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -72,7 +72,8 @@ data Packet = | |||
72 | timestamp::Word32, | 72 | timestamp::Word32, |
73 | content::LZ.ByteString | 73 | content::LZ.ByteString |
74 | } | | 74 | } | |
75 | UserIDPacket String | 75 | UserIDPacket String | |
76 | UnsupportedPacket Word8 LZ.ByteString | ||
76 | deriving (Show, Read, Eq) | 77 | deriving (Show, Read, Eq) |
77 | 78 | ||
78 | instance Binary Packet where | 79 | instance Binary Packet where |
@@ -259,6 +260,7 @@ put_packet (LiteralDataPacket { format = format, filename = filename, | |||
259 | filename_l = (fromIntegral $ LZ.length lz_filename) :: Word8 | 260 | filename_l = (fromIntegral $ LZ.length lz_filename) :: Word8 |
260 | lz_filename = LZ.fromString filename | 261 | lz_filename = LZ.fromString filename |
261 | put_packet (UserIDPacket txt) = (LZ.fromString txt, 13) | 262 | put_packet (UserIDPacket txt) = (LZ.fromString txt, 13) |
263 | put_packet (UnsupportedPacket tag bytes) = (bytes, fromIntegral tag) | ||
262 | put_packet _ = error "Unsupported Packet version or type in put_packet." | 264 | put_packet _ = error "Unsupported Packet version or type in put_packet." |
263 | 265 | ||
264 | parse_packet :: Word8 -> Get Packet | 266 | parse_packet :: Word8 -> Get Packet |
@@ -390,8 +392,8 @@ parse_packet 11 = do | |||
390 | -- UserIDPacket, http://tools.ietf.org/html/rfc4880#section-5.11 | 392 | -- UserIDPacket, http://tools.ietf.org/html/rfc4880#section-5.11 |
391 | parse_packet 13 = | 393 | parse_packet 13 = |
392 | fmap (UserIDPacket . LZ.toString) getRemainingLazyByteString | 394 | fmap (UserIDPacket . LZ.toString) getRemainingLazyByteString |
393 | -- Fail nicely for unimplemented packets | 395 | -- Represent unsupported packets as their tag and literal bytes |
394 | parse_packet x = fail $ "Unimplemented OpenPGP packet tag " ++ show x ++ "." | 396 | parse_packet tag = fmap (UnsupportedPacket tag) getRemainingLazyByteString |
395 | 397 | ||
396 | -- | Helper method for fingerprints and such | 398 | -- | Helper method for fingerprints and such |
397 | fingerprint_material :: Packet -> [LZ.ByteString] | 399 | fingerprint_material :: Packet -> [LZ.ByteString] |
@@ -547,7 +549,8 @@ instance Binary MPI where | |||
547 | 549 | ||
548 | data SignatureSubpacket = | 550 | data SignatureSubpacket = |
549 | SignatureCreationTimePacket Word32 | | 551 | SignatureCreationTimePacket Word32 | |
550 | IssuerPacket String | 552 | IssuerPacket String | |
553 | UnsupportedSignatureSubpacket Word8 LZ.ByteString | ||
551 | deriving (Show, Read, Eq) | 554 | deriving (Show, Read, Eq) |
552 | 555 | ||
553 | instance Binary SignatureSubpacket where | 556 | instance Binary SignatureSubpacket where |
@@ -590,6 +593,8 @@ put_signature_subpacket (SignatureCreationTimePacket time) = | |||
590 | (encode time, 2) | 593 | (encode time, 2) |
591 | put_signature_subpacket (IssuerPacket keyid) = | 594 | put_signature_subpacket (IssuerPacket keyid) = |
592 | (encode (BaseConvert.toNum 16 keyid :: Word64), 16) | 595 | (encode (BaseConvert.toNum 16 keyid :: Word64), 16) |
596 | put_signature_subpacket (UnsupportedSignatureSubpacket tag bytes) = | ||
597 | (bytes, tag) | ||
593 | 598 | ||
594 | get_signature_subpackets :: Get [SignatureSubpacket] | 599 | get_signature_subpackets :: Get [SignatureSubpacket] |
595 | get_signature_subpackets = do | 600 | get_signature_subpackets = do |
@@ -607,9 +612,9 @@ parse_signature_subpacket 2 = fmap SignatureCreationTimePacket get | |||
607 | parse_signature_subpacket 16 = do | 612 | parse_signature_subpacket 16 = do |
608 | keyid <- get :: Get Word64 | 613 | keyid <- get :: Get Word64 |
609 | return $ IssuerPacket (BaseConvert.toString 16 keyid) | 614 | return $ IssuerPacket (BaseConvert.toString 16 keyid) |
610 | -- Fail nicely for unimplemented packets | 615 | -- Represent unsupported packets as their tag and literal bytes |
611 | parse_signature_subpacket x = | 616 | parse_signature_subpacket tag = |
612 | fail $ "Unimplemented OpenPGP signature subpacket tag " ++ show x ++ "." | 617 | fmap (UnsupportedSignatureSubpacket tag) getRemainingLazyByteString |
613 | 618 | ||
614 | decode_s2k_count :: Word8 -> Word32 | 619 | decode_s2k_count :: Word8 -> Word32 |
615 | decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL` | 620 | decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL` |