diff options
author | joe <joe@jerkface.net> | 2016-08-26 01:21:22 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-01 09:19:55 -0400 |
commit | 7909c13a18e260af68819be7444829f799cb7c38 (patch) | |
tree | 3cb6f79309555b5638d2fe71af1c3a219a4d7f8b /Data/OpenPGP/Util/Fingerprint.hs | |
parent | becfa261ce50d9976c3720aaacd06e48488300af (diff) |
WIP: support for cryptonite.
Diffstat (limited to 'Data/OpenPGP/Util/Fingerprint.hs')
-rw-r--r-- | Data/OpenPGP/Util/Fingerprint.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Data/OpenPGP/Util/Fingerprint.hs b/Data/OpenPGP/Util/Fingerprint.hs index 538688b..20b6e72 100644 --- a/Data/OpenPGP/Util/Fingerprint.hs +++ b/Data/OpenPGP/Util/Fingerprint.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | module Data.OpenPGP.Util.Fingerprint (fingerprint) where | 2 | module Data.OpenPGP.Util.Fingerprint (fingerprint) where |
2 | 3 | ||
3 | import qualified Data.OpenPGP as OpenPGP | 4 | import qualified Data.OpenPGP as OpenPGP |
@@ -7,17 +8,32 @@ import Data.Char (toUpper) | |||
7 | import Data.Word (Word8) | 8 | import Data.Word (Word8) |
8 | import Numeric (showHex) | 9 | import Numeric (showHex) |
9 | 10 | ||
11 | #if defined(VERSION_cryptonite) | ||
12 | import Crypto.Hash.Algorithms | ||
13 | import Crypto.Hash | ||
14 | import qualified Data.ByteArray as Bytes | ||
15 | #else | ||
10 | import Crypto.Hash.MD5 as MD5 | 16 | import Crypto.Hash.MD5 as MD5 |
11 | import Crypto.Hash.SHA1 as SHA1 | 17 | import Crypto.Hash.SHA1 as SHA1 |
18 | #endif | ||
12 | 19 | ||
13 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket | 20 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket |
14 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> | 21 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> |
15 | fingerprint :: OpenPGP.Packet -> String | 22 | fingerprint :: OpenPGP.Packet -> String |
16 | fingerprint p | 23 | fingerprint p |
17 | | OpenPGP.version p == 4 = hexify $ SHA1.hashlazy material | 24 | | OpenPGP.version p == 4 = hexify $ sha1 material |
18 | | OpenPGP.version p `elem` [2, 3] = hexify $ MD5.hashlazy material | 25 | | OpenPGP.version p `elem` [2, 3] = hexify $ md5 material |
19 | | otherwise = error "Unsupported Packet version or type in fingerprint" | 26 | | otherwise = error "Unsupported Packet version or type in fingerprint" |
20 | where | 27 | where |
28 | |||
29 | #if defined(VERSION_cryptonite) | ||
30 | sha1 x = Bytes.convert (hashlazy x :: Digest SHA1) | ||
31 | md5 x = Bytes.convert (hashlazy x :: Digest MD5) | ||
32 | #else | ||
33 | sha1 = SHA1.hashlazy | ||
34 | md5 = MD5.hashlazy | ||
35 | #endif | ||
36 | |||
21 | material = LZ.concat $ OpenPGP.fingerprint_material p | 37 | material = LZ.concat $ OpenPGP.fingerprint_material p |
22 | 38 | ||
23 | hexify = map toUpper . hexString . BS.unpack | 39 | hexify = map toUpper . hexString . BS.unpack |