diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-12-29 10:52:15 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-12-29 10:52:15 -0500 |
commit | 86d6407eccd1ed9f44f4e1a0e495e504d393c1d8 (patch) | |
tree | 65fb0fa6fd1ce5e25394d1982449c931f589e844 | |
parent | c431df57562913b0f8a80badcff3293354cea86e (diff) |
AsymmetricSessionKeyPacket
-rw-r--r-- | Arbitrary.patch | 4 | ||||
-rw-r--r-- | Data/OpenPGP.hs | 21 |
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 |
7 | module Data.OpenPGP ( | 7 | module 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 ( | |||
63 | import Numeric | 64 | import Numeric |
64 | import Control.Monad | 65 | import Control.Monad |
65 | import Control.Arrow | 66 | import Control.Arrow |
67 | import Control.Applicative | ||
66 | import Control.Exception (assert) | 68 | import Control.Exception (assert) |
67 | import Data.Bits | 69 | import Data.Bits |
68 | import Data.Word | 70 | import Data.Word |
@@ -155,6 +157,12 @@ pad :: Int -> String -> String | |||
155 | pad l s = replicate (l - length s) '0' ++ s | 157 | pad l s = replicate (l - length s) '0' ++ s |
156 | 158 | ||
157 | data Packet = | 159 | data 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 | ||
341 | put_packet :: Packet -> (B.ByteString, Word8) | 349 | put_packet :: Packet -> (B.ByteString, Word8) |
350 | put_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) | ||
342 | put_packet (SignaturePacket { version = v, | 357 | put_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) | |||
456 | put_packet x = error ("Unsupported Packet version or type in put_packet: " ++ show x) | 471 | put_packet x = error ("Unsupported Packet version or type in put_packet: " ++ show x) |
457 | 472 | ||
458 | parse_packet :: Word8 -> Get Packet | 473 | parse_packet :: Word8 -> Get Packet |
474 | -- AsymmetricSessionKeyPacket, http://tools.ietf.org/html/rfc4880#section-5.1 | ||
475 | parse_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 |
460 | parse_packet 2 = do | 481 | parse_packet 2 = do |
461 | version <- get | 482 | version <- get |