diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-15 18:49:22 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-15 18:49:42 -0400 |
commit | d6e03020851601668cf5419950ca0cc49e54c42f (patch) | |
tree | 92b92842fab5563496d2e0f65a28c3343de87050 /Data | |
parent | beed56fec5bbef22f198fd99e05873080313bdae (diff) |
Switched fingerprint to a wrapped ByteString.
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP/Util/Base.hs | 2 | ||||
-rw-r--r-- | Data/OpenPGP/Util/Fingerprint.hs | 37 | ||||
-rw-r--r-- | Data/OpenPGP/Util/Sign.hs | 2 |
3 files changed, 23 insertions, 18 deletions
diff --git a/Data/OpenPGP/Util/Base.hs b/Data/OpenPGP/Util/Base.hs index c1088d8..5b3e159 100644 --- a/Data/OpenPGP/Util/Base.hs +++ b/Data/OpenPGP/Util/Base.hs | |||
@@ -82,7 +82,7 @@ toLazyBS :: BS.ByteString -> LZ.ByteString | |||
82 | toLazyBS = LZ.fromChunks . (:[]) | 82 | toLazyBS = LZ.fromChunks . (:[]) |
83 | 83 | ||
84 | find_key :: OpenPGP.Message -> String -> Maybe OpenPGP.Packet | 84 | find_key :: OpenPGP.Message -> String -> Maybe OpenPGP.Packet |
85 | find_key = OpenPGP.find_key fingerprint | 85 | find_key = OpenPGP.find_key (show . fingerprint) |
86 | 86 | ||
87 | 87 | ||
88 | 88 | ||
diff --git a/Data/OpenPGP/Util/Fingerprint.hs b/Data/OpenPGP/Util/Fingerprint.hs index 20b6e72..b2e3904 100644 --- a/Data/OpenPGP/Util/Fingerprint.hs +++ b/Data/OpenPGP/Util/Fingerprint.hs | |||
@@ -1,5 +1,5 @@ | |||
1 | {-# LANGUAGE CPP #-} | 1 | {-# LANGUAGE CPP #-} |
2 | module Data.OpenPGP.Util.Fingerprint (fingerprint) where | 2 | module Data.OpenPGP.Util.Fingerprint (fingerprint,Fingerprint(..)) where |
3 | 3 | ||
4 | import qualified Data.OpenPGP as OpenPGP | 4 | import qualified Data.OpenPGP as OpenPGP |
5 | import qualified Data.ByteString as BS | 5 | import qualified Data.ByteString as BS |
@@ -17,12 +17,29 @@ import Crypto.Hash.MD5 as MD5 | |||
17 | import Crypto.Hash.SHA1 as SHA1 | 17 | import Crypto.Hash.SHA1 as SHA1 |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | oo :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c | ||
21 | oo = (.) . (.) | ||
22 | |||
23 | newtype Fingerprint = Fingerprint BS.ByteString | ||
24 | |||
25 | instance Show Fingerprint where | ||
26 | show (Fingerprint bs) = hexify bs | ||
27 | where | ||
28 | hexify = map toUpper . hexString . BS.unpack | ||
29 | |||
30 | hexString :: [Word8] -> String | ||
31 | hexString = foldr (pad `oo` showHex) "" | ||
32 | where | ||
33 | pad s | odd $ length s = '0':s | ||
34 | | otherwise = s | ||
35 | |||
36 | |||
20 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket | 37 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket |
21 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> | 38 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> |
22 | fingerprint :: OpenPGP.Packet -> String | 39 | fingerprint :: OpenPGP.Packet -> Fingerprint |
23 | fingerprint p | 40 | fingerprint p |
24 | | OpenPGP.version p == 4 = hexify $ sha1 material | 41 | | OpenPGP.version p == 4 = Fingerprint $ sha1 material |
25 | | OpenPGP.version p `elem` [2, 3] = hexify $ md5 material | 42 | | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material |
26 | | otherwise = error "Unsupported Packet version or type in fingerprint" | 43 | | otherwise = error "Unsupported Packet version or type in fingerprint" |
27 | where | 44 | where |
28 | 45 | ||
@@ -35,15 +52,3 @@ fingerprint p | |||
35 | #endif | 52 | #endif |
36 | 53 | ||
37 | material = LZ.concat $ OpenPGP.fingerprint_material p | 54 | material = LZ.concat $ OpenPGP.fingerprint_material p |
38 | |||
39 | hexify = map toUpper . hexString . BS.unpack | ||
40 | |||
41 | hexString :: [Word8] -> String | ||
42 | hexString = foldr (pad `oo` showHex) "" | ||
43 | where | ||
44 | pad s | odd $ length s = '0':s | ||
45 | | otherwise = s | ||
46 | |||
47 | oo :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c | ||
48 | oo = (.) . (.) | ||
49 | |||
diff --git a/Data/OpenPGP/Util/Sign.hs b/Data/OpenPGP/Util/Sign.hs index 8663a0d..d96c3a7 100644 --- a/Data/OpenPGP/Util/Sign.hs +++ b/Data/OpenPGP/Util/Sign.hs | |||
@@ -115,7 +115,7 @@ unsafeSign keys over hsh keyid timestamp g = (over {OpenPGP.signatures_over = [s | |||
115 | ([ | 115 | ([ |
116 | -- Do we really need to pass in timestamp just for the default? | 116 | -- Do we really need to pass in timestamp just for the default? |
117 | OpenPGP.SignatureCreationTimePacket $ fromIntegral timestamp, | 117 | OpenPGP.SignatureCreationTimePacket $ fromIntegral timestamp, |
118 | OpenPGP.IssuerPacket $ fingerprint k | 118 | OpenPGP.IssuerPacket $ show $ fingerprint k |
119 | ] ++ (case over of | 119 | ] ++ (case over of |
120 | OpenPGP.KeySignature {} -> [OpenPGP.KeyFlagsPacket { | 120 | OpenPGP.KeySignature {} -> [OpenPGP.KeyFlagsPacket { |
121 | OpenPGP.certify_keys = True, | 121 | OpenPGP.certify_keys = True, |