blob: 2a1303d97ec299eb1bbf3bc9eb79b0f668e86f95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
{-# LANGUAGE CApiFFI #-}
{-# OPTIONS_GHC -Wno-missing-methods #-}
module Data.Digest.Md5
( md5
) where
import Data.ByteString.Lazy (ByteString)
import Foreign (Ptr, Storable(alignment, sizeOf))
import Foreign.C.Types
import Data.Digest.Internal
#include <openssl/md5.h>
data Md5Ctx
instance Storable Md5Ctx where
sizeOf _ = #size MD5_CTX
alignment _ = #alignment MD5_CTX
foreign import capi "openssl/md5.h value MD5_DIGEST_LENGTH"
md5DigestLength :: CSize
foreign import ccall "openssl/md5.h MD5_Init"
md5Init :: Ptr Md5Ctx -> IO CInt
foreign import ccall "openssl/md5.h MD5_Update"
md5Update :: Ptr Md5Ctx -> Ptr a -> CSize -> IO CInt
foreign import ccall "openssl/md5.h MD5_Final"
md5Final :: Ptr CUChar -> Ptr Md5Ctx -> IO CInt
md5Algo :: Algo
md5Algo = Algo md5DigestLength md5Init md5Update md5Final
md5 :: ByteString -> Digest
md5 = hash md5Algo
|