summaryrefslogtreecommitdiff
path: root/Data
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-04-24 17:50:08 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-04-24 17:50:08 -0500
commit4df371631b16d753dd262171ec82c3ebaea42a10 (patch)
treeaaeb82a909ded1a588bc9507d2b72e5cdc8b0a8c /Data
parenta47e1ba41aef9276d7654e602fd7445cad0e1355 (diff)
Represent unsupported packets and subpackets by their literal bytes
Diffstat (limited to 'Data')
-rw-r--r--Data/OpenPGP.hs19
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
78instance Binary Packet where 79instance 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
261put_packet (UserIDPacket txt) = (LZ.fromString txt, 13) 262put_packet (UserIDPacket txt) = (LZ.fromString txt, 13)
263put_packet (UnsupportedPacket tag bytes) = (bytes, fromIntegral tag)
262put_packet _ = error "Unsupported Packet version or type in put_packet." 264put_packet _ = error "Unsupported Packet version or type in put_packet."
263 265
264parse_packet :: Word8 -> Get Packet 266parse_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
391parse_packet 13 = 393parse_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
394parse_packet x = fail $ "Unimplemented OpenPGP packet tag " ++ show x ++ "." 396parse_packet tag = fmap (UnsupportedPacket tag) getRemainingLazyByteString
395 397
396-- | Helper method for fingerprints and such 398-- | Helper method for fingerprints and such
397fingerprint_material :: Packet -> [LZ.ByteString] 399fingerprint_material :: Packet -> [LZ.ByteString]
@@ -547,7 +549,8 @@ instance Binary MPI where
547 549
548data SignatureSubpacket = 550data 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
553instance Binary SignatureSubpacket where 556instance Binary SignatureSubpacket where
@@ -590,6 +593,8 @@ put_signature_subpacket (SignatureCreationTimePacket time) =
590 (encode time, 2) 593 (encode time, 2)
591put_signature_subpacket (IssuerPacket keyid) = 594put_signature_subpacket (IssuerPacket keyid) =
592 (encode (BaseConvert.toNum 16 keyid :: Word64), 16) 595 (encode (BaseConvert.toNum 16 keyid :: Word64), 16)
596put_signature_subpacket (UnsupportedSignatureSubpacket tag bytes) =
597 (bytes, tag)
593 598
594get_signature_subpackets :: Get [SignatureSubpacket] 599get_signature_subpackets :: Get [SignatureSubpacket]
595get_signature_subpackets = do 600get_signature_subpackets = do
@@ -607,9 +612,9 @@ parse_signature_subpacket 2 = fmap SignatureCreationTimePacket get
607parse_signature_subpacket 16 = do 612parse_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
611parse_signature_subpacket x = 616parse_signature_subpacket tag =
612 fail $ "Unimplemented OpenPGP signature subpacket tag " ++ show x ++ "." 617 fmap (UnsupportedSignatureSubpacket tag) getRemainingLazyByteString
613 618
614decode_s2k_count :: Word8 -> Word32 619decode_s2k_count :: Word8 -> Word32
615decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL` 620decode_s2k_count c = (16 + (fromIntegral c .&. 15)) `shiftL`