summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util/Fingerprint.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/OpenPGP/Util/Fingerprint.hs')
-rw-r--r--Data/OpenPGP/Util/Fingerprint.hs20
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 #-}
2module Data.OpenPGP.Util.Fingerprint (fingerprint,Fingerprint(..),hex) where 2module Data.OpenPGP.Util.Fingerprint (fingerprint,fingerprintv,Fingerprint(..),hex) where
3 3
4import qualified Data.OpenPGP as OpenPGP 4import qualified Data.OpenPGP as OpenPGP
5import qualified Data.ByteString as BS 5import qualified Data.ByteString as BS
6import qualified Data.ByteString.Lazy as LZ 6import qualified Data.ByteString.Lazy as LZ
7import Data.Char (toUpper) 7import Data.Char (toUpper)
8import Data.Word (Word8) 8import Data.Word (Word8)
9import GHC.Stack
9import Numeric (showHex) 10import 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>
42fingerprint :: OpenPGP.Packet -> Fingerprint 43fingerprint :: HasCallStack => OpenPGP.Packet -> Fingerprint
43fingerprint p 44fingerprint 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 46fingerprintv :: HasCallStack => Word8 -> OpenPGP.Packet -> Fingerprint
46 | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material 47fingerprintv 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