summaryrefslogtreecommitdiff
path: root/Data
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2011-08-08 23:52:15 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2011-08-08 23:52:15 -0500
commita4b22e4d7606699f6b10238aa245fa53be339d3e (patch)
tree89e006f721f42d1de845ea2778be9851a5de447e /Data
parent86f5e6145e92fd234a062e8807b2efe30f28cd0e (diff)
hlint clean
Diffstat (limited to 'Data')
-rw-r--r--Data/OpenPGP.hs82
1 files changed, 40 insertions, 42 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs
index 0ce9991..fd89cfb 100644
--- a/Data/OpenPGP.hs
+++ b/Data/OpenPGP.hs
@@ -115,7 +115,7 @@ parse_new_length = do
115-- http://tools.ietf.org/html/rfc4880#section-4.2.1 115-- http://tools.ietf.org/html/rfc4880#section-4.2.1
116parse_old_length :: Word8 -> Get Word32 116parse_old_length :: Word8 -> Get Word32
117parse_old_length tag = 117parse_old_length tag =
118 case (tag .&. 3) of 118 case tag .&. 3 of
119 -- One octet length 119 -- One octet length
120 0 -> fmap fromIntegral (get :: Get Word8) 120 0 -> fmap fromIntegral (get :: Get Word8)
121 -- Two octet length 121 -- Two octet length
@@ -154,7 +154,7 @@ signature_packet_start (SignaturePacket {
154 hash_algorithm = hash_algorithm, 154 hash_algorithm = hash_algorithm,
155 hashed_subpackets = hashed_subpackets 155 hashed_subpackets = hashed_subpackets
156}) = 156}) =
157 LZ.concat $ [ 157 LZ.concat [
158 encode (0x04 :: Word8), 158 encode (0x04 :: Word8),
159 encode signature_type, 159 encode signature_type,
160 encode key_algorithm, 160 encode key_algorithm,
@@ -173,7 +173,7 @@ calculate_signature_trailer p =
173 signature_packet_start p, 173 signature_packet_start p,
174 encode (0x04 :: Word8), 174 encode (0x04 :: Word8),
175 encode (0xff :: Word8), 175 encode (0xff :: Word8),
176 encode ((fromIntegral (LZ.length $ signature_packet_start p)) :: Word32) 176 encode (fromIntegral (LZ.length $ signature_packet_start p) :: Word32)
177 ] 177 ]
178 178
179put_packet :: (Num a) => Packet -> (LZ.ByteString, a) 179put_packet :: (Num a) => Packet -> (LZ.ByteString, a)
@@ -224,8 +224,8 @@ put_packet (SecretKeyPacket { version = version, timestamp = timestamp,
224 (if s2k_useage == 254 then 224 (if s2k_useage == 254 then
225 [LZ.replicate 20 0] -- TODO SHA1 Checksum 225 [LZ.replicate 20 0] -- TODO SHA1 Checksum
226 else 226 else
227 [encode $ (fromIntegral $ 227 [encode (fromIntegral $
228 LZ.foldl (\c i -> (c + (fromIntegral i)) `mod` 65536) 228 LZ.foldl (\c i -> (c + fromIntegral i) `mod` 65536)
229 (0::Integer) (LZ.concat s) :: Word16)]), 5) 229 (0::Integer) (LZ.concat s) :: Word16)]), 5)
230 where 230 where
231 p = fst (put_packet $ 231 p = fst (put_packet $
@@ -273,7 +273,7 @@ parse_packet 2 = do
273 let unhashed = runGet get_signature_subpackets unhashed_data 273 let unhashed = runGet get_signature_subpackets unhashed_data
274 hash_head <- get 274 hash_head <- get
275 signature <- get 275 signature <- get
276 return (SignaturePacket { 276 return SignaturePacket {
277 version = version, 277 version = version,
278 signature_type = signature_type, 278 signature_type = signature_type,
279 key_algorithm = key_algorithm, 279 key_algorithm = key_algorithm,
@@ -282,9 +282,9 @@ parse_packet 2 = do
282 unhashed_subpackets = unhashed, 282 unhashed_subpackets = unhashed,
283 hash_head = hash_head, 283 hash_head = hash_head,
284 signature = signature, 284 signature = signature,
285 trailer = LZ.concat [encode version, encode signature_type, encode key_algorithm, encode hash_algorithm, encode (fromIntegral hashed_size :: Word16), hashed_data, LZ.pack [4, 0xff], encode ((6 + (fromIntegral hashed_size)) :: Word32)] 285 trailer = LZ.concat [encode version, encode signature_type, encode key_algorithm, encode hash_algorithm, encode (fromIntegral hashed_size :: Word16), hashed_data, LZ.pack [4, 0xff], encode ((6 + fromIntegral hashed_size) :: Word32)]
286 }) 286 }
287 x -> fail $ "Unknown SignaturePacket version " ++ (show x) ++ "." 287 x -> fail $ "Unknown SignaturePacket version " ++ show x ++ "."
288-- OnePassSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.4 288-- OnePassSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.4
289parse_packet 4 = do 289parse_packet 4 = do
290 version <- get 290 version <- get
@@ -293,14 +293,14 @@ parse_packet 4 = do
293 key_algo <- get 293 key_algo <- get
294 key_id <- get :: Get Word64 294 key_id <- get :: Get Word64
295 nested <- get 295 nested <- get
296 return (OnePassSignaturePacket { 296 return OnePassSignaturePacket {
297 version = version, 297 version = version,
298 signature_type = signature_type, 298 signature_type = signature_type,
299 hash_algorithm = hash_algo, 299 hash_algorithm = hash_algo,
300 key_algorithm = key_algo, 300 key_algorithm = key_algo,
301 key_id = (BaseConvert.toString 16 key_id), 301 key_id = BaseConvert.toString 16 key_id,
302 nested = nested 302 nested = nested
303 }) 303 }
304-- SecretKeyPacket, http://tools.ietf.org/html/rfc4880#section-5.5.3 304-- SecretKeyPacket, http://tools.ietf.org/html/rfc4880#section-5.5.3
305parse_packet 5 = do 305parse_packet 5 = do
306 -- Parse PublicKey part 306 -- Parse PublicKey part
@@ -350,13 +350,13 @@ parse_packet 6 = do
350 key <- mapM (\f -> do 350 key <- mapM (\f -> do
351 mpi <- get :: Get MPI 351 mpi <- get :: Get MPI
352 return (f, mpi)) (public_key_fields algorithm) 352 return (f, mpi)) (public_key_fields algorithm)
353 return (PublicKeyPacket { 353 return PublicKeyPacket {
354 version = 4, 354 version = 4,
355 timestamp = timestamp, 355 timestamp = timestamp,
356 key_algorithm = algorithm, 356 key_algorithm = algorithm,
357 key = Map.fromList key 357 key = Map.fromList key
358 }) 358 }
359 x -> fail $ "Unsupported PublicKeyPacket version " ++ (show x) ++ "." 359 x -> fail $ "Unsupported PublicKeyPacket version " ++ show x ++ "."
360-- CompressedDataPacket, http://tools.ietf.org/html/rfc4880#section-5.6 360-- CompressedDataPacket, http://tools.ietf.org/html/rfc4880#section-5.6
361parse_packet 8 = do 361parse_packet 8 = do
362 algorithm <- get 362 algorithm <- get
@@ -366,10 +366,10 @@ parse_packet 8 = do
366 ZIP -> Zip.decompress 366 ZIP -> Zip.decompress
367 ZLIB -> Zlib.decompress 367 ZLIB -> Zlib.decompress
368 BZip2 -> BZip2.decompress 368 BZip2 -> BZip2.decompress
369 return (CompressedDataPacket { 369 return CompressedDataPacket {
370 compression_algorithm = algorithm, 370 compression_algorithm = algorithm,
371 message = runGet (get :: Get Message) (decompress message) 371 message = runGet (get :: Get Message) (decompress message)
372 }) 372 }
373-- LiteralDataPacket, http://tools.ietf.org/html/rfc4880#section-5.9 373-- LiteralDataPacket, http://tools.ietf.org/html/rfc4880#section-5.9
374parse_packet 11 = do 374parse_packet 11 = do
375 format <- get 375 format <- get
@@ -377,17 +377,17 @@ parse_packet 11 = do
377 filename <- getLazyByteString (fromIntegral filenameLength) 377 filename <- getLazyByteString (fromIntegral filenameLength)
378 timestamp <- get 378 timestamp <- get
379 content <- getRemainingLazyByteString 379 content <- getRemainingLazyByteString
380 return (LiteralDataPacket { 380 return LiteralDataPacket {
381 format = format, 381 format = format,
382 filename = LZ.toString filename, 382 filename = LZ.toString filename,
383 timestamp = timestamp, 383 timestamp = timestamp,
384 content = content 384 content = content
385 }) 385 }
386-- UserIDPacket, http://tools.ietf.org/html/rfc4880#section-5.11 386-- UserIDPacket, http://tools.ietf.org/html/rfc4880#section-5.11
387parse_packet 13 = 387parse_packet 13 =
388 fmap UserIDPacket (fmap LZ.toString getRemainingLazyByteString) 388 fmap (UserIDPacket . LZ.toString) getRemainingLazyByteString
389-- Fail nicely for unimplemented packets 389-- Fail nicely for unimplemented packets
390parse_packet x = fail $ "Unimplemented OpenPGP packet tag " ++ (show x) ++ "." 390parse_packet x = fail $ "Unimplemented OpenPGP packet tag " ++ show x ++ "."
391 391
392-- | Helper method for fingerprints and such 392-- | Helper method for fingerprints and such
393fingerprint_material :: Packet -> [LZ.ByteString] 393fingerprint_material :: Packet -> [LZ.ByteString]
@@ -403,7 +403,7 @@ fingerprint_material (PublicKeyPacket {version = 4,
403 ] 403 ]
404 where material = LZ.concat $ 404 where material = LZ.concat $
405 map (\f -> encode (key ! f)) (public_key_fields algorithm) 405 map (\f -> encode (key ! f)) (public_key_fields algorithm)
406fingerprint_material p | (version p) `elem` [2, 3] = [n, e] 406fingerprint_material p | version p `elem` [2, 3] = [n, e]
407 where n = LZ.drop 2 (encode (key p ! 'n')) 407 where n = LZ.drop 2 (encode (key p ! 'n'))
408 e = LZ.drop 2 (encode (key p ! 'e')) 408 e = LZ.drop 2 (encode (key p ! 'e'))
409fingerprint_material _ = 409fingerprint_material _ =
@@ -429,7 +429,7 @@ instance Binary HashAlgorithm where
429 09 -> return SHA384 429 09 -> return SHA384
430 10 -> return SHA512 430 10 -> return SHA512
431 11 -> return SHA224 431 11 -> return SHA224
432 x -> fail $ "Unknown HashAlgorithm " ++ (show x) ++ "." 432 x -> fail $ "Unknown HashAlgorithm " ++ show x ++ "."
433 433
434data KeyAlgorithm = RSA | RSA_E | RSA_S | ELGAMAL | DSA | ECC | ECDSA | DH 434data KeyAlgorithm = RSA | RSA_E | RSA_S | ELGAMAL | DSA | ECC | ECDSA | DH
435 deriving (Show, Read, Eq) 435 deriving (Show, Read, Eq)
@@ -453,7 +453,7 @@ instance Binary KeyAlgorithm where
453 18 -> return ECC 453 18 -> return ECC
454 19 -> return ECDSA 454 19 -> return ECDSA
455 21 -> return DH 455 21 -> return DH
456 x -> fail $ "Unknown KeyAlgorithm " ++ (show x) ++ "." 456 x -> fail $ "Unknown KeyAlgorithm " ++ show x ++ "."
457 457
458data CompressionAlgorithm = Uncompressed | ZIP | ZLIB | BZip2 458data CompressionAlgorithm = Uncompressed | ZIP | ZLIB | BZip2
459 deriving (Show, Read, Eq) 459 deriving (Show, Read, Eq)
@@ -469,7 +469,7 @@ instance Binary CompressionAlgorithm where
469 1 -> return ZIP 469 1 -> return ZIP
470 2 -> return ZLIB 470 2 -> return ZLIB
471 3 -> return BZip2 471 3 -> return BZip2
472 x -> fail $ "Unknown CompressionAlgorithm " ++ (show x) ++ "." 472 x -> fail $ "Unknown CompressionAlgorithm " ++ show x ++ "."
473 473
474-- A message is encoded as a list that takes the entire file 474-- A message is encoded as a list that takes the entire file
475newtype Message = Message [Packet] deriving (Show, Read, Eq) 475newtype Message = Message [Packet] deriving (Show, Read, Eq)
@@ -480,12 +480,11 @@ instance Binary Message where
480 put (Message xs) 480 put (Message xs)
481 get = do 481 get = do
482 done <- isEmpty 482 done <- isEmpty
483 if done then do { 483 if done then return (Message []) else do {
484 return (Message []); 484 next_packet <- get :: Get Packet;
485 } else do 485 (Message tail) <- get :: Get Message;
486 next_packet <- get :: Get Packet 486 return (Message (next_packet:tail));
487 (Message tail) <- get :: Get Message 487 }
488 return (Message (next_packet:tail))
489 488
490-- | Extract all signature and data packets from a 'Message' 489-- | Extract all signature and data packets from a 'Message'
491signatures_and_data :: Message -> ([Packet], [Packet]) 490signatures_and_data :: Message -> ([Packet], [Packet])
@@ -522,7 +521,7 @@ instance Binary SignatureSubpacket where
522 put p = do 521 put p = do
523 -- Use 5-octet-length + 1 for tag as the first packet body octet 522 -- Use 5-octet-length + 1 for tag as the first packet body octet
524 put (255 :: Word8) 523 put (255 :: Word8)
525 put ((fromIntegral $ LZ.length body) + 1 :: Word32) 524 put (fromIntegral (LZ.length body) + 1 :: Word32)
526 put tag 525 put tag
527 putLazyByteString body 526 putLazyByteString body
528 where (body, tag) = put_signature_subpacket p 527 where (body, tag) = put_signature_subpacket p
@@ -545,9 +544,9 @@ instance Binary SignatureSubpacket where
545signature_issuer :: Packet -> Maybe String 544signature_issuer :: Packet -> Maybe String
546signature_issuer (SignaturePacket {hashed_subpackets = hashed, 545signature_issuer (SignaturePacket {hashed_subpackets = hashed,
547 unhashed_subpackets = unhashed}) = 546 unhashed_subpackets = unhashed}) =
548 if (length issuers) > 0 then Just issuer else Nothing 547 if length issuers > 0 then Just issuer else Nothing
549 where IssuerPacket issuer = issuers !! 0 548 where IssuerPacket issuer = issuers !! 0
550 issuers = (filter isIssuer hashed) ++ (filter isIssuer unhashed) 549 issuers = filter isIssuer hashed ++ filter isIssuer unhashed
551 isIssuer (IssuerPacket {}) = True 550 isIssuer (IssuerPacket {}) = True
552 isIssuer _ = False 551 isIssuer _ = False
553signature_issuer _ = Nothing 552signature_issuer _ = Nothing
@@ -556,17 +555,16 @@ put_signature_subpacket :: SignatureSubpacket -> (LZ.ByteString, Word8)
556put_signature_subpacket (SignatureCreationTimePacket time) = 555put_signature_subpacket (SignatureCreationTimePacket time) =
557 (encode time, 2) 556 (encode time, 2)
558put_signature_subpacket (IssuerPacket keyid) = 557put_signature_subpacket (IssuerPacket keyid) =
559 (encode ((BaseConvert.toNum 16 keyid) :: Word64), 16) 558 (encode (BaseConvert.toNum 16 keyid :: Word64), 16)
560 559
561get_signature_subpackets :: Get [SignatureSubpacket] 560get_signature_subpackets :: Get [SignatureSubpacket]
562get_signature_subpackets = do 561get_signature_subpackets = do
563 done <- isEmpty 562 done <- isEmpty
564 if done then do { 563 if done then return [] else do {
565 return []; 564 next_packet <- get :: Get SignatureSubpacket;
566 } else do 565 tail <- get_signature_subpackets;
567 next_packet <- get :: Get SignatureSubpacket 566 return (next_packet:tail);
568 tail <- get_signature_subpackets 567 }
569 return (next_packet:tail)
570 568
571parse_signature_subpacket :: Word8 -> Get SignatureSubpacket 569parse_signature_subpacket :: Word8 -> Get SignatureSubpacket
572-- SignatureCreationTimePacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.4 570-- SignatureCreationTimePacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.4
@@ -577,4 +575,4 @@ parse_signature_subpacket 16 = do
577 return $ IssuerPacket (BaseConvert.toString 16 keyid) 575 return $ IssuerPacket (BaseConvert.toString 16 keyid)
578-- Fail nicely for unimplemented packets 576-- Fail nicely for unimplemented packets
579parse_signature_subpacket x = 577parse_signature_subpacket x =
580 fail $ "Unimplemented OpenPGP signature subpacket tag " ++ (show x) ++ "." 578 fail $ "Unimplemented OpenPGP signature subpacket tag " ++ show x ++ "."