-- |-- Module : Crypto.Hash.Types-- License : BSD-style-- Maintainer : Vincent Hanquez <vincent@snarc.org>-- Stability : experimental-- Portability : unknown---- Crypto hash types definitions--moduleCrypto.Hash.Types(HashAlgorithm(..),Context(..),Digest(..))whereimportData.ByteString(ByteString)importqualifiedData.ByteString.Char8asBCimportCrypto.Hash.Utils(toHex)-- | Class representing hashing algorithms.---- The hash algorithm is built over 3 primitives:---- init : create a new context-- updates : update the context with some strict bytestrings-- finalize : finalize the context into a digest--classHashAlgorithmawhere-- | Initialize a new context for this hash algorithmhashInit::Contexta-- | Update the context with a list of strict bytestring,-- and return a new context with the updates.hashUpdates::Contexta->[ByteString]->Contexta-- | Finalize a context and return a digest.hashFinalize::Contexta->Digesta-- | Try to convert a binary digest bytestring to a digest.digestFromByteString::ByteString->Maybe(Digesta)-- | Represent a context for a given hash algorithm.newtypeContexta=Context{contextToByteString::ByteString}-- | Represent a digest for a given hash algorithm.newtypeDigesta=Digest{digestToByteString::ByteString-- ^ Return the binary digest}deriving(Eq,Ord)instanceShow(Digesta)whereshow(Digestbs)=BC.unpack$toHexbs