module Cryptol.ModuleSystem.Fingerprint
( Fingerprint
, fingerprint
, fingerprintFile
) where
import Control.DeepSeq (NFData (rnf))
import Crypto.Hash.SHA1 (hash)
import Data.ByteString (ByteString)
import Control.Exception (try)
import qualified Data.ByteString as B
newtype Fingerprint = Fingerprint ByteString
deriving (Eq, Show)
instance NFData Fingerprint where
rnf (Fingerprint fp) = rnf fp
fingerprint :: ByteString -> Fingerprint
fingerprint = Fingerprint . hash
fingerprintFile :: FilePath -> IO (Maybe Fingerprint)
fingerprintFile path =
do res <- try (B.readFile path)
return $!
case res :: Either IOError ByteString of
Left{} -> Nothing
Right b -> Just $! fingerprint b