Permalink
Browse files

EmbeddedSignaturePacket

  • Loading branch information...
1 parent 9877a30 commit 905e4e82e295b2fa0f547e7c8d458c3f35944bcc @singpolyma committed Apr 30, 2012
Showing with 24 additions and 5 deletions.
  1. +13 −3 Arbitrary.patch
  2. +11 −2 Data/OpenPGP.hs
View
@@ -1,12 +1,19 @@
--- Data/OpenPGP/Arbitrary.hs 2012-04-27 12:38:11.492411339 -0500
+++ arb.s 2012-04-27 12:37:57.176469214 -0500
-@@ -19,8 +19,7 @@
+@@ -14,13 +14,11 @@
+ 0 -> do x1 <- arbitrary
+ x2 <- arbitrary
+ x3 <- arbitrary
+- x4 <- arbitrary
+- x5 <- arbitrary
++ x4 <- resize 10 (listOf arbitrary)
++ x5 <- resize 10 (listOf arbitrary)
x6 <- arbitrary
x7 <- arbitrary
- x8 <- arbitrary
+- x8 <- arbitrary
- x9 <- arbitrary
- return (SignaturePacket x1 x2 x3 x4 x5 x6 x7 x8 x9)
-+ return (signaturePacket x1 x2 x3 x4 x5 x6 x7 x8)
++ return (signaturePacket 4 x1 x2 x3 x4 x5 x6 x7)
1 -> do x1 <- arbitrary
x2 <- arbitrary
x3 <- arbitrary
@@ -74,6 +81,9 @@
@@ -166 +165 @@
- 9 -> do x1 <- arbitrary
+ 9 -> do x1 <- vectorOf 16 (elements (['0'..'9'] ++ ['A'..'F']))
+@@ -217 +216 @@
+- 22 -> do x1 <- arbitrary
++ 22 -> do x1 <- suchThat arbitrary isSignaturePacket
@@ -169,2 +168 @@
- x2 <- arbitrary
- return (UnsupportedSignatureSubpacket x1 x2)
View
@@ -289,8 +289,8 @@ signature_packet_start (SignaturePacket {
]
where
hashed_subs = B.concat $ map encode hashed_subpackets
-signature_packet_start _ =
- error "Trying to get start of signature packet for non signature packet."
+signature_packet_start x =
+ error ("Trying to get start of signature packet for: " ++ show x)
-- The trailer is just the top of the body plus some crap
calculate_signature_trailer :: Packet -> B.ByteString
@@ -749,6 +749,7 @@ data SignatureSubpacket =
target_hash_algorithm::HashAlgorithm,
hash::B.ByteString
} |
+ EmbeddedSignaturePacket Packet |
UnsupportedSignatureSubpacket Word8 B.ByteString
deriving (Show, Read, Eq)
@@ -850,6 +851,8 @@ put_signature_subpacket (FeaturesPacket supports_mdc) =
(B.singleton $ if supports_mdc then 0x01 else 0x00, 30)
put_signature_subpacket (SignatureTargetPacket kalgo halgo hash) =
(B.concat [encode kalgo, encode halgo, hash], 31)
+put_signature_subpacket (EmbeddedSignaturePacket packet) =
+ (encode (assert (isSignaturePacket packet) packet), 32)
put_signature_subpacket (UnsupportedSignatureSubpacket tag bytes) =
(bytes, tag)
@@ -962,6 +965,12 @@ parse_signature_subpacket 30 = do
-- SignatureTargetPacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.25
parse_signature_subpacket 31 =
liftM3 SignatureTargetPacket get get getRemainingByteString
+-- EmbeddedSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.26
+parse_signature_subpacket 32 =
+ fmap (EmbeddedSignaturePacket . forceSignature) get
+ where
+ forceSignature x@(SignaturePacket {}) = x
+ forceSignature _ = error "EmbeddedSignature must contain signature"
-- Represent unsupported packets as their tag and literal bytes
parse_signature_subpacket tag =
fmap (UnsupportedSignatureSubpacket tag) getRemainingByteString

0 comments on commit 905e4e8

Please sign in to comment.