summaryrefslogtreecommitdiff
path: root/Data
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-04-24 09:05:28 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-04-24 09:05:28 -0500
commitcb5c1644b6540939e8d5aa1b8fef80b797577166 (patch)
treed925b3e9747089c44417190eb8b7fdcb6746a498 /Data
parent051e4b171782df1a384c3fc5763c69e35d9f46ba (diff)
some formatting cleanup
Diffstat (limited to 'Data')
-rw-r--r--Data/OpenPGP.hs54
1 files changed, 31 insertions, 23 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index 3693d06..affc940 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -83,7 +83,8 @@ instance Binary Packet where
83 put (255 :: Word8) 83 put (255 :: Word8)
84 put ((fromIntegral $ LZ.length body) :: Word32) 84 put ((fromIntegral $ LZ.length body) :: Word32)
85 putLazyByteString body 85 putLazyByteString body
86 where (body, tag) = put_packet p 86 where
87 (body, tag) = put_packet p
87 get = do 88 get = do
88 tag <- get :: Get Word8 89 tag <- get :: Get Word8
89 let (t, l) = 90 let (t, l) =
@@ -162,7 +163,8 @@ signature_packet_start (SignaturePacket {
162 encode ((fromIntegral $ LZ.length hashed_subs) :: Word16), 163 encode ((fromIntegral $ LZ.length hashed_subs) :: Word16),
163 hashed_subs 164 hashed_subs
164 ] 165 ]
165 where hashed_subs = LZ.concat $ map encode hashed_subpackets 166 where
167 hashed_subs = LZ.concat $ map encode hashed_subpackets
166signature_packet_start _ = 168signature_packet_start _ =
167 error "Trying to get start of signature packet for non signature packet." 169 error "Trying to get start of signature packet for non signature packet."
168 170
@@ -192,8 +194,9 @@ put_packet (SignaturePacket { version = 4,
192 encode (fromIntegral $ LZ.length unhashed :: Word16), 194 encode (fromIntegral $ LZ.length unhashed :: Word16),
193 unhashed, 195 unhashed,
194 encode hash_head, encode signature ], 2) 196 encode hash_head, encode signature ], 2)
195 where hashed = LZ.concat $ map encode hashed_subpackets 197 where
196 unhashed = LZ.concat $ map encode unhashed_subpackets 198 hashed = LZ.concat $ map encode hashed_subpackets
199 unhashed = LZ.concat $ map encode unhashed_subpackets
197put_packet (OnePassSignaturePacket { version = version, 200put_packet (OnePassSignaturePacket { version = version,
198 signature_type = signature_type, 201 signature_type = signature_type,
199 hash_algorithm = hash_algorithm, 202 hash_algorithm = hash_algorithm,
@@ -228,14 +231,13 @@ put_packet (SecretKeyPacket { version = version, timestamp = timestamp,
228 LZ.foldl (\c i -> (c + fromIntegral i) `mod` 65536) 231 LZ.foldl (\c i -> (c + fromIntegral i) `mod` 65536)
229 (0::Integer) (LZ.concat s) :: Word16)]), 5) 232 (0::Integer) (LZ.concat s) :: Word16)]), 5)
230 where 233 where
231 p = fst (put_packet $ 234 p = fst (put_packet $ PublicKeyPacket version timestamp algorithm key
232 PublicKeyPacket version timestamp algorithm key
233 :: (LZ.ByteString, Integer)) -- Supress warning 235 :: (LZ.ByteString, Integer)) -- Supress warning
234 s = map (encode . (key !)) (secret_key_fields algorithm) 236 s = map (encode . (key !)) (secret_key_fields algorithm)
235put_packet (PublicKeyPacket { version = 4, timestamp = timestamp, 237put_packet (PublicKeyPacket { version = 4, timestamp = timestamp,
236 key_algorithm = algorithm, key = key }) = 238 key_algorithm = algorithm, key = key }) =
237 (LZ.concat $ [LZ.singleton 4, encode timestamp, encode algorithm] ++ 239 (LZ.concat $ [LZ.singleton 4, encode timestamp, encode algorithm] ++
238 map (encode . (key !)) (public_key_fields algorithm), 6) 240 map (encode . (key !)) (public_key_fields algorithm), 6)
239put_packet (CompressedDataPacket { compression_algorithm = algorithm, 241put_packet (CompressedDataPacket { compression_algorithm = algorithm,
240 message = message }) = 242 message = message }) =
241 (LZ.append (encode algorithm) $ compress $ encode message, 8) 243 (LZ.append (encode algorithm) $ compress $ encode message, 8)
@@ -401,8 +403,9 @@ fingerprint_material (PublicKeyPacket {version = 4,
401 LZ.singleton 4, encode timestamp, encode algorithm, 403 LZ.singleton 4, encode timestamp, encode algorithm,
402 material 404 material
403 ] 405 ]
404 where material = LZ.concat $ 406 where
405 map (\f -> encode (key ! f)) (public_key_fields algorithm) 407 material =
408 LZ.concat $ map (encode . (key !)) (public_key_fields algorithm)
406-- Proxy to make SecretKeyPacket work 409-- Proxy to make SecretKeyPacket work
407fingerprint_material (SecretKeyPacket {version = 4, 410fingerprint_material (SecretKeyPacket {version = 4,
408 timestamp = timestamp, 411 timestamp = timestamp,
@@ -413,8 +416,9 @@ fingerprint_material (SecretKeyPacket {version = 4,
413 key_algorithm = algorithm, 416 key_algorithm = algorithm,
414 key = key} 417 key = key}
415fingerprint_material p | version p `elem` [2, 3] = [n, e] 418fingerprint_material p | version p `elem` [2, 3] = [n, e]
416 where n = LZ.drop 2 (encode (key p ! 'n')) 419 where
417 e = LZ.drop 2 (encode (key p ! 'e')) 420 n = LZ.drop 2 (encode (key p ! 'n'))
421 e = LZ.drop 2 (encode (key p ! 'e'))
418fingerprint_material _ = 422fingerprint_material _ =
419 error "Unsupported Packet version or type in fingerprint_material." 423 error "Unsupported Packet version or type in fingerprint_material."
420 424
@@ -489,11 +493,10 @@ instance Binary Message where
489 put (Message xs) 493 put (Message xs)
490 get = do 494 get = do
491 done <- isEmpty 495 done <- isEmpty
492 if done then return (Message []) else do { 496 if done then return (Message []) else do
493 next_packet <- get :: Get Packet; 497 next_packet <- get
494 (Message tail) <- get :: Get Message; 498 (Message tail) <- get
495 return (Message (next_packet:tail)); 499 return (Message (next_packet:tail))
496 }
497 500
498-- | Extract all signature and data packets from a 'Message' 501-- | Extract all signature and data packets from a 'Message'
499signatures_and_data :: Message -> ([Packet], [Packet]) 502signatures_and_data :: Message -> ([Packet], [Packet])
@@ -501,10 +504,11 @@ signatures_and_data (Message ((CompressedDataPacket {message = m}):_)) =
501 signatures_and_data m 504 signatures_and_data m
502signatures_and_data (Message lst) = 505signatures_and_data (Message lst) =
503 (filter isSig lst, filter isDta lst) 506 (filter isSig lst, filter isDta lst)
504 where isSig (SignaturePacket {}) = True 507 where
505 isSig _ = False 508 isSig (SignaturePacket {}) = True
506 isDta (LiteralDataPacket {}) = True 509 isSig _ = False
507 isDta _ = False 510 isDta (LiteralDataPacket {}) = True
511 isDta _ = False
508 512
509newtype MPI = MPI Integer deriving (Show, Read, Eq, Ord) 513newtype MPI = MPI Integer deriving (Show, Read, Eq, Ord)
510instance Binary MPI where 514instance Binary MPI where
@@ -513,8 +517,11 @@ instance Binary MPI where
513 + floor (logBase (2::Double) $ fromIntegral (bytes `LZ.index` 0)) 517 + floor (logBase (2::Double) $ fromIntegral (bytes `LZ.index` 0))
514 + 1 :: Word16) 518 + 1 :: Word16)
515 putLazyByteString bytes 519 putLazyByteString bytes
516 where bytes = LZ.reverse $ LZ.unfoldr (\x -> if x == 0 then Nothing 520 where
517 else Just (fromIntegral x, x `shiftR` 8)) i 521 bytes = LZ.reverse $ LZ.unfoldr (\x ->
522 if x == 0 then Nothing else
523 Just (fromIntegral x, x `shiftR` 8)
524 ) i
518 get = do 525 get = do
519 length <- fmap fromIntegral (get :: Get Word16) 526 length <- fmap fromIntegral (get :: Get Word16)
520 bytes <- getLazyByteString ((length + 7) `div` 8) 527 bytes <- getLazyByteString ((length + 7) `div` 8)
@@ -533,7 +540,8 @@ instance Binary SignatureSubpacket where
533 put (fromIntegral (LZ.length body) + 1 :: Word32) 540 put (fromIntegral (LZ.length body) + 1 :: Word32)
534 put tag 541 put tag
535 putLazyByteString body 542 putLazyByteString body
536 where (body, tag) = put_signature_subpacket p 543 where
544 (body, tag) = put_signature_subpacket p
537 get = do 545 get = do
538 len <- fmap fromIntegral (get :: Get Word8) 546 len <- fmap fromIntegral (get :: Get Word8)
539 len <- case len of 547 len <- case len of