summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-12-29 10:52:15 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-12-29 10:52:15 -0500
commit86d6407eccd1ed9f44f4e1a0e495e504d393c1d8 (patch)
tree65fb0fa6fd1ce5e25394d1982449c931f589e844
parentc431df57562913b0f8a80badcff3293354cea86e (diff)
AsymmetricSessionKeyPacket
-rw-r--r--Arbitrary.patch4
-rw-r--r--Data/OpenPGP.hs21
2 files changed, 23 insertions, 2 deletions
diff --git a/Arbitrary.patch b/Arbitrary.patch
index fa78846..641609f 100644
--- a/Arbitrary.patch
+++ b/Arbitrary.patch
@@ -1,7 +1,7 @@
1--- Data/OpenPGP/Arbitrary.hs 2012-04-27 12:38:11.492411339 -0500 1--- Data/OpenPGP/Arbitrary.hs 2012-04-27 12:38:11.492411339 -0500
2+++ arb.s 2012-04-27 12:37:57.176469214 -0500 2+++ arb.s 2012-04-27 12:37:57.176469214 -0500
3@@ -14,13 +14,18 @@ 3@@ -14,13 +14,18 @@
4 0 -> do x1 <- arbitrary 4 1 -> do x1 <- arbitrary
5 x2 <- arbitrary 5 x2 <- arbitrary
6 x3 <- arbitrary 6 x3 <- arbitrary
7- x4 <- arbitrary 7- x4 <- arbitrary
@@ -21,7 +21,7 @@
21+ creation_time <- arbitrary 21+ creation_time <- arbitrary
22+ keyid <- vectorOf 16 (elements (['0'..'9'] ++ ['A'..'F'])) 22+ keyid <- vectorOf 16 (elements (['0'..'9'] ++ ['A'..'F']))
23+ return (signaturePacket version x1 x2 x3 [] [SignatureCreationTimePacket creation_time, IssuerPacket keyid] x6 x7) 23+ return (signaturePacket version x1 x2 x3 [] [SignatureCreationTimePacket creation_time, IssuerPacket keyid] x6 x7)
24 1 -> do x1 <- arbitrary 24 2 -> do x1 <- arbitrary
25 x2 <- arbitrary 25 x2 <- arbitrary
26 x3 <- arbitrary 26 x3 <- arbitrary
27@@ -73,7 +72,7 @@ 27@@ -73,7 +72,7 @@
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index c9a7840..dca7838 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -6,6 +6,7 @@
6-- > import qualified Data.OpenPGP as OpenPGP 6-- > import qualified Data.OpenPGP as OpenPGP
7module Data.OpenPGP ( 7module Data.OpenPGP (
8 Packet( 8 Packet(
9 AsymmetricSessionKeyPacket,
9 OnePassSignaturePacket, 10 OnePassSignaturePacket,
10 PublicKeyPacket, 11 PublicKeyPacket,
11 SecretKeyPacket, 12 SecretKeyPacket,
@@ -63,6 +64,7 @@ module Data.OpenPGP (
63import Numeric 64import Numeric
64import Control.Monad 65import Control.Monad
65import Control.Arrow 66import Control.Arrow
67import Control.Applicative
66import Control.Exception (assert) 68import Control.Exception (assert)
67import Data.Bits 69import Data.Bits
68import Data.Word 70import Data.Word
@@ -155,6 +157,12 @@ pad :: Int -> String -> String
155pad l s = replicate (l - length s) '0' ++ s 157pad l s = replicate (l - length s) '0' ++ s
156 158
157data Packet = 159data Packet =
160 AsymmetricSessionKeyPacket {
161 version::Word8,
162 key_id::String,
163 key_algorithm::KeyAlgorithm,
164 encrypted_data::B.ByteString
165 } |
158 SignaturePacket { 166 SignaturePacket {
159 version::Word8, 167 version::Word8,
160 signature_type::Word8, 168 signature_type::Word8,
@@ -339,6 +347,13 @@ calculate_signature_trailer x =
339 error ("Trying to calculate signature trailer for: " ++ show x) 347 error ("Trying to calculate signature trailer for: " ++ show x)
340 348
341put_packet :: Packet -> (B.ByteString, Word8) 349put_packet :: Packet -> (B.ByteString, Word8)
350put_packet (AsymmetricSessionKeyPacket version key_id key_algorithm dta) =
351 (B.concat [
352 encode version,
353 encode (fst $ head $ readHex key_id :: Word64),
354 encode key_algorithm,
355 dta
356 ], 1)
342put_packet (SignaturePacket { version = v, 357put_packet (SignaturePacket { version = v,
343 unhashed_subpackets = unhashed_subpackets, 358 unhashed_subpackets = unhashed_subpackets,
344 key_algorithm = key_algorithm, 359 key_algorithm = key_algorithm,
@@ -456,6 +471,12 @@ put_packet (UnsupportedPacket tag bytes) = (bytes, fromIntegral tag)
456put_packet x = error ("Unsupported Packet version or type in put_packet: " ++ show x) 471put_packet x = error ("Unsupported Packet version or type in put_packet: " ++ show x)
457 472
458parse_packet :: Word8 -> Get Packet 473parse_packet :: Word8 -> Get Packet
474-- AsymmetricSessionKeyPacket, http://tools.ietf.org/html/rfc4880#section-5.1
475parse_packet 1 = AsymmetricSessionKeyPacket
476 <$> fmap (assertProp (==3)) get
477 <*> fmap (pad 16 . map toUpper . flip showHex "") (get :: Get Word64)
478 <*> get
479 <*> getRemainingByteString
459-- SignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.2 480-- SignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.2
460parse_packet 2 = do 481parse_packet 2 = do
461 version <- get 482 version <- get