module Data.X509.Validation.Fingerprint
( Fingerprint(..)
, getFingerprint
, toDescr
) where
import Crypto.PubKey.HashDescr
import Data.X509
import Data.ASN1.Types
import Data.ByteString (ByteString)
import Data.Byteable
newtype Fingerprint = Fingerprint ByteString
deriving (Show,Eq)
instance Byteable Fingerprint where
toBytes (Fingerprint bs) = bs
getFingerprint :: (Show a, Eq a, ASN1Object a)
=> SignedExact a
-> HashALG
-> Fingerprint
getFingerprint sobj halg = Fingerprint $ hashF $ encodeSignedObject sobj
where hashDescr = toDescr halg
hashF = hashFunction hashDescr
toDescr :: HashALG -> HashDescr
toDescr HashMD2 = hashDescrMD2
toDescr HashMD5 = hashDescrMD5
toDescr HashSHA1 = hashDescrSHA1
toDescr HashSHA224 = hashDescrSHA224
toDescr HashSHA256 = hashDescrSHA256
toDescr HashSHA384 = hashDescrSHA384
toDescr HashSHA512 = hashDescrSHA512