Debian Codegraph @

Data/X509/Validation/Fingerprint.hs

raw
1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2
3 -- |
4 -- Module : Data.X509.Validation.Fingerprint
5 -- License : BSD-style
6 -- Maintainer : Vincent Hanquez <[email protected]>
7 -- Stability : experimental
8 -- Portability : unknown
9 module Data.X509.Validation.Fingerprint (
10 Fingerprint (..),
11 getFingerprint,
12 ) where
13
14 import Crypto.Hash
15 import Data.ASN1.Types
16 import Data.ByteArray (ByteArrayAccess, convert)
17 import Data.ByteString (ByteString)
18 import Data.X509
19
20 -- | Fingerprint of a certificate
21 newtype Fingerprint = Fingerprint ByteString
22 deriving (Show, Eq, ByteArrayAccess)
23
24 -- | Get the fingerprint of the whole signed object
25 -- using the hashing algorithm specified
26 getFingerprint
27 :: (Show a, Eq a, ASN1Object a)
28 => SignedExact a
29 -- ^ object to fingerprint
30 -> HashALG
31 -- ^ algorithm to compute the fingerprint
32 -> Fingerprint
33 -- ^ fingerprint in binary form
34 getFingerprint sobj halg = Fingerprint $ mkHash halg $ encodeSignedObject sobj
35 where
36 mkHash HashMD2 = convert . hashWith MD2
37 mkHash HashMD5 = convert . hashWith MD5
38 mkHash HashSHA1 = convert . hashWith SHA1
39 mkHash HashSHA224 = convert . hashWith SHA224
40 mkHash HashSHA256 = convert . hashWith SHA256
41 mkHash HashSHA384 = convert . hashWith SHA384
42 mkHash HashSHA512 = convert . hashWith SHA512