diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-12-29 10:45:35 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-12-29 10:45:35 -0500 |
commit | a0405223def95a6d8238d4ac25c4ea8eb6523a0c (patch) | |
tree | 79667c212f545048b5f5439fcd01df9ce7976d0c /Data | |
parent | d08a1a3693acf4558a6f53ee21585cb7664aeac1 (diff) |
Share pad function
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP.hs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index ccdc70a..e0d0501 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -151,6 +151,9 @@ lazyDecompress x = error ("No implementation for " ++ show x) | |||
151 | assertProp :: (a -> Bool) -> a -> a | 151 | assertProp :: (a -> Bool) -> a -> a |
152 | assertProp f x = assert (f x) x | 152 | assertProp f x = assert (f x) x |
153 | 153 | ||
154 | pad :: Int -> String -> String | ||
155 | pad l s = replicate (l - length s) '0' ++ s | ||
156 | |||
154 | data Packet = | 157 | data Packet = |
155 | SignaturePacket { | 158 | SignaturePacket { |
156 | version::Word8, | 159 | version::Word8, |
@@ -475,7 +478,7 @@ parse_packet 2 = do | |||
475 | hashed_subpackets = [], | 478 | hashed_subpackets = [], |
476 | unhashed_subpackets = [ | 479 | unhashed_subpackets = [ |
477 | SignatureCreationTimePacket creation_time, | 480 | SignatureCreationTimePacket creation_time, |
478 | IssuerPacket $ pad $ map toUpper $ showHex keyid "" | 481 | IssuerPacket $ pad 16 $ map toUpper $ showHex keyid "" |
479 | ], | 482 | ], |
480 | hash_head = hash_head, | 483 | hash_head = hash_head, |
481 | signature = signature, | 484 | signature = signature, |
@@ -505,8 +508,6 @@ parse_packet 2 = do | |||
505 | trailer = B.concat [encode version, encode signature_type, encode key_algorithm, encode hash_algorithm, encode (fromIntegral hashed_size :: Word16), hashed_data, B.pack [4, 0xff], encode ((6 + fromIntegral hashed_size) :: Word32)] | 508 | trailer = B.concat [encode version, encode signature_type, encode key_algorithm, encode hash_algorithm, encode (fromIntegral hashed_size :: Word16), hashed_data, B.pack [4, 0xff], encode ((6 + fromIntegral hashed_size) :: Word32)] |
506 | } | 509 | } |
507 | x -> fail $ "Unknown SignaturePacket version " ++ show x ++ "." | 510 | x -> fail $ "Unknown SignaturePacket version " ++ show x ++ "." |
508 | where | ||
509 | pad s = replicate (16 - length s) '0' ++ s | ||
510 | -- OnePassSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.4 | 511 | -- OnePassSignaturePacket, http://tools.ietf.org/html/rfc4880#section-5.4 |
511 | parse_packet 4 = do | 512 | parse_packet 4 = do |
512 | version <- get | 513 | version <- get |
@@ -520,11 +521,9 @@ parse_packet 4 = do | |||
520 | signature_type = signature_type, | 521 | signature_type = signature_type, |
521 | hash_algorithm = hash_algo, | 522 | hash_algorithm = hash_algo, |
522 | key_algorithm = key_algo, | 523 | key_algorithm = key_algo, |
523 | key_id = pad $ map toUpper $ showHex key_id "", | 524 | key_id = pad 16 $ map toUpper $ showHex key_id "", |
524 | nested = nested | 525 | nested = nested |
525 | } | 526 | } |
526 | where | ||
527 | pad s = replicate (16 - length s) '0' ++ s | ||
528 | -- SecretKeyPacket, http://tools.ietf.org/html/rfc4880#section-5.5.3 | 527 | -- SecretKeyPacket, http://tools.ietf.org/html/rfc4880#section-5.5.3 |
529 | parse_packet 5 = do | 528 | parse_packet 5 = do |
530 | -- Parse PublicKey part | 529 | -- Parse PublicKey part |
@@ -1005,19 +1004,16 @@ parse_signature_subpacket 12 = do | |||
1005 | sensitive = bitfield .&. 0x40 == 0x40, | 1004 | sensitive = bitfield .&. 0x40 == 0x40, |
1006 | revocation_key_algorithm = kalgo, | 1005 | revocation_key_algorithm = kalgo, |
1007 | revocation_key_fingerprint = | 1006 | revocation_key_fingerprint = |
1008 | pad $ map toUpper $ foldr (padB `oo` showHex) "" (B.unpack fpr) | 1007 | pad 40 $ map toUpper $ foldr (padB `oo` showHex) "" (B.unpack fpr) |
1009 | } | 1008 | } |
1010 | where | 1009 | where |
1011 | oo = (.) . (.) | 1010 | oo = (.) . (.) |
1012 | padB s | odd $ length s = '0':s | 1011 | padB s | odd $ length s = '0':s |
1013 | | otherwise = s | 1012 | | otherwise = s |
1014 | pad s = replicate (40 - length s) '0' ++ s | ||
1015 | -- IssuerPacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.5 | 1013 | -- IssuerPacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.5 |
1016 | parse_signature_subpacket 16 = do | 1014 | parse_signature_subpacket 16 = do |
1017 | keyid <- get :: Get Word64 | 1015 | keyid <- get :: Get Word64 |
1018 | return $ IssuerPacket (pad $ map toUpper $ showHex keyid "") | 1016 | return $ IssuerPacket (pad 16 $ map toUpper $ showHex keyid "") |
1019 | where | ||
1020 | pad s = replicate (16 - length s) '0' ++ s | ||
1021 | -- NotationDataPacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.16 | 1017 | -- NotationDataPacket, http://tools.ietf.org/html/rfc4880#section-5.2.3.16 |
1022 | parse_signature_subpacket 20 = do | 1018 | parse_signature_subpacket 20 = do |
1023 | (flag1,_,_,_) <- get4word8 | 1019 | (flag1,_,_,_) <- get4word8 |