diff options
Diffstat (limited to 'Data/OpenPGP/Util/Fingerprint.hs')
-rw-r--r-- | Data/OpenPGP/Util/Fingerprint.hs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Data/OpenPGP/Util/Fingerprint.hs b/Data/OpenPGP/Util/Fingerprint.hs index d88661b..cda25f6 100644 --- a/Data/OpenPGP/Util/Fingerprint.hs +++ b/Data/OpenPGP/Util/Fingerprint.hs | |||
@@ -1,11 +1,12 @@ | |||
1 | {-# LANGUAGE CPP #-} | 1 | {-# LANGUAGE CPP #-} |
2 | module Data.OpenPGP.Util.Fingerprint (fingerprint,Fingerprint(..),hex) where | 2 | module Data.OpenPGP.Util.Fingerprint (fingerprint,fingerprintv,Fingerprint(..),hex) 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 |
6 | import qualified Data.ByteString.Lazy as LZ | 6 | import qualified Data.ByteString.Lazy as LZ |
7 | import Data.Char (toUpper) | 7 | import Data.Char (toUpper) |
8 | import Data.Word (Word8) | 8 | import Data.Word (Word8) |
9 | import GHC.Stack | ||
9 | import Numeric (showHex) | 10 | import Numeric (showHex) |
10 | 11 | ||
11 | #if defined(VERSION_cryptonite) | 12 | #if defined(VERSION_cryptonite) |
@@ -39,12 +40,15 @@ hex (Fingerprint bs) = hexify bs | |||
39 | 40 | ||
40 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket | 41 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket |
41 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> | 42 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> |
42 | fingerprint :: OpenPGP.Packet -> Fingerprint | 43 | fingerprint :: HasCallStack => OpenPGP.Packet -> Fingerprint |
43 | fingerprint p | 44 | fingerprint p = fingerprintv (OpenPGP.auto_fp_version p) p |
44 | | OpenPGP.version p == 5 = Fingerprint $ sha256 material | 45 | |
45 | | OpenPGP.version p == 4 = Fingerprint $ sha1 material | 46 | fingerprintv :: HasCallStack => Word8 -> OpenPGP.Packet -> Fingerprint |
46 | | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material | 47 | fingerprintv v p = case v of |
47 | | otherwise = error "Unsupported Packet version or type in fingerprint" | 48 | 5 -> Fingerprint $ sha256 material |
49 | 4 -> Fingerprint $ sha1 material | ||
50 | 3 -> Fingerprint $ md5 material | ||
51 | _ -> error "Unsupported Packet version or type in fingerprint" | ||
48 | where | 52 | where |
49 | 53 | ||
50 | #if defined(VERSION_cryptonite) | 54 | #if defined(VERSION_cryptonite) |
@@ -57,4 +61,4 @@ fingerprint p | |||
57 | md5 = MD5.hashlazy | 61 | md5 = MD5.hashlazy |
58 | #endif | 62 | #endif |
59 | 63 | ||
60 | material = LZ.concat $ OpenPGP.fingerprint_material p | 64 | material = LZ.concat $ OpenPGP.fingerprint_materialv v p |