{-# LANGUAGE PackageImports #-}
module Crypto.Hash.MD2
( Ctx(..)
, init
, update
, updates
, finalize
, hash
, hashlazy
) where
import Prelude hiding (init)
import qualified Data.ByteString.Lazy as L
import Data.ByteString (ByteString)
import Crypto.Hash.Internal (digestToByteString, digestToByteStringWitness)
import qualified "cryptonite" Crypto.Hash as H
newtype Ctx = Ctx (H.Context H.MD2)
init :: Ctx
init :: Ctx
init = Context MD2 -> Ctx
Ctx forall a. HashAlgorithm a => Context a
H.hashInit
update :: Ctx -> ByteString -> Ctx
update :: Ctx -> ByteString -> Ctx
update (Ctx Context MD2
ctx) ByteString
d = Context MD2 -> Ctx
Ctx forall a b. (a -> b) -> a -> b
$ forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
Context a -> ba -> Context a
H.hashUpdate Context MD2
ctx ByteString
d
updates :: Ctx -> [ByteString] -> Ctx
updates :: Ctx -> [ByteString] -> Ctx
updates (Ctx Context MD2
ctx) [ByteString]
d =
Context MD2 -> Ctx
Ctx forall a b. (a -> b) -> a -> b
$ forall a ba.
(HashAlgorithm a, ByteArrayAccess ba) =>
Context a -> [ba] -> Context a
H.hashUpdates Context MD2
ctx [ByteString]
d
finalize :: Ctx -> ByteString
finalize :: Ctx -> ByteString
finalize (Ctx Context MD2
ctx) = forall h. HashAlgorithm h => Digest h -> ByteString
digestToByteString forall a b. (a -> b) -> a -> b
$ forall a. HashAlgorithm a => Context a -> Digest a
H.hashFinalize Context MD2
ctx
hash :: ByteString -> ByteString
hash :: ByteString -> ByteString
hash ByteString
d = forall h. HashAlgorithm h => h -> Digest h -> ByteString
digestToByteStringWitness MD2
H.MD2 forall a b. (a -> b) -> a -> b
$ forall ba a.
(ByteArrayAccess ba, HashAlgorithm a) =>
ba -> Digest a
H.hash ByteString
d
hashlazy :: L.ByteString -> ByteString
hashlazy :: ByteString -> ByteString
hashlazy ByteString
l = forall h. HashAlgorithm h => h -> Digest h -> ByteString
digestToByteStringWitness MD2
H.MD2 forall a b. (a -> b) -> a -> b
$ forall a. HashAlgorithm a => ByteString -> Digest a
H.hashlazy ByteString
l