diff options
Diffstat (limited to 'Data/OpenPGP.hs')
-rw-r--r-- | Data/OpenPGP.hs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index 3064dc5..bee718a 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -59,6 +59,8 @@ module Data.OpenPGP ( | |||
59 | MPI(..), | 59 | MPI(..), |
60 | find_key, | 60 | find_key, |
61 | fingerprint_material, | 61 | fingerprint_material, |
62 | auto_fp_version, | ||
63 | fingerprint_materialv, | ||
62 | SignatureOver(..), | 64 | SignatureOver(..), |
63 | signatures, | 65 | signatures, |
64 | signature_issuer, | 66 | signature_issuer, |
@@ -843,9 +845,17 @@ parse_packet 19 = | |||
843 | -- Represent unsupported packets as their tag and literal bytes | 845 | -- Represent unsupported packets as their tag and literal bytes |
844 | parse_packet tag = fmap (UnsupportedPacket tag) getRemainingByteString | 846 | parse_packet tag = fmap (UnsupportedPacket tag) getRemainingByteString |
845 | 847 | ||
848 | auto_fp_version :: Packet -> Word8 | ||
849 | auto_fp_version p | version p == 2 = 3 | ||
850 | | otherwise = version p | ||
851 | |||
852 | -- | Helper method for fingerprints and such | ||
853 | fingerprint_material :: HasCallStack => Packet -> [B.ByteString] | ||
854 | fingerprint_material p = fingerprint_materialv (auto_fp_version p) p | ||
855 | |||
846 | -- | Helper method for fingerprints and such | 856 | -- | Helper method for fingerprints and such |
847 | fingerprint_material :: Packet -> [B.ByteString] | 857 | fingerprint_materialv :: HasCallStack => Word8 -> Packet -> [B.ByteString] |
848 | fingerprint_material p | version p == 5 = | 858 | fingerprint_materialv 5 p = |
849 | [ | 859 | [ |
850 | B.singleton 0x9A, | 860 | B.singleton 0x9A, |
851 | encode (10 + fromIntegral (B.length material) :: Word32), | 861 | encode (10 + fromIntegral (B.length material) :: Word32), |
@@ -855,7 +865,7 @@ fingerprint_material p | version p == 5 = | |||
855 | ] | 865 | ] |
856 | where | 866 | where |
857 | material = B.concat $ encode_public_key_material p | 867 | material = B.concat $ encode_public_key_material p |
858 | fingerprint_material p | version p == 4 = | 868 | fingerprint_materialv 4 p = |
859 | [ | 869 | [ |
860 | B.singleton 0x99, | 870 | B.singleton 0x99, |
861 | encode (6 + fromIntegral (B.length material) :: Word16), | 871 | encode (6 + fromIntegral (B.length material) :: Word16), |
@@ -864,11 +874,11 @@ fingerprint_material p | version p == 4 = | |||
864 | ] | 874 | ] |
865 | where | 875 | where |
866 | material = B.concat $ encode_public_key_material p | 876 | material = B.concat $ encode_public_key_material p |
867 | fingerprint_material p | version p `elem` [2, 3] = [n, e] | 877 | fingerprint_materialv 3 p | key_algorithm p == RSA = [n, e] |
868 | where | 878 | where |
869 | n = B.drop 2 (encode (key p ! 'n')) | 879 | n = B.drop 2 (encode (key p ! 'n')) |
870 | e = B.drop 2 (encode (key p ! 'e')) | 880 | e = B.drop 2 (encode (key p ! 'e')) |
871 | fingerprint_material _ = | 881 | fingerprint_materialv _ _ = |
872 | error "Unsupported Packet version or type in fingerprint_material." | 882 | error "Unsupported Packet version or type in fingerprint_material." |
873 | 883 | ||
874 | enum_to_word8 :: (Enum a) => a -> Word8 | 884 | enum_to_word8 :: (Enum a) => a -> Word8 |