@@ -66,7 +66,7 @@ data CryptHandle
66msDefProv :: String
66msDefProv :: String
67msDefProv = "Microsoft Base Cryptographic Provider v1.0"
67msDefProv = "Microsoft Base Cryptographic Provider v1.0"
68provRSAFull :: Word32
68provRSAFull :: Word32
69−provRSAFull = fromIntegral 1
69+provRSAFull = 1
70cryptVerifyContext :: Word32
70cryptVerifyContext :: Word32
71cryptVerifyContext = fromIntegral 0xF0000000
71cryptVerifyContext = fromIntegral 0xF0000000
@@ -79,10 +79,10 @@ foreign import stdcall unsafe "CryptReleaseContext"
79 c_cryptReleaseCtx :: Word32 -> Word32 -> IO Int32
79 c_cryptReleaseCtx :: Word32 -> Word32 -> IO Int32
81cryptAcquireCtx :: IO Word32
81cryptAcquireCtx :: IO Word32
82−cryptAcquireCtx =
82+cryptAcquireCtx =
83 alloca $ \handlePtr ->
83 alloca $ \handlePtr ->
84 withCString msDefProv $ \provName -> do
84 withCString msDefProv $ \provName -> do
85− stat <- c_cryptAcquireCtx handlePtr nullPtr provName (fromIntegral 1) (fromIntegral cryptVerifyContext)
85+ stat <- c_cryptAcquireCtx handlePtr nullPtr provName provRSAFull cryptVerifyContext
86 if (toBool stat)
86 if (toBool stat)
87 then peek handlePtr
87 then peek handlePtr
88 else fail "c_cryptAcquireCtx"
88 else fail "c_cryptAcquireCtx"
@@ -90,7 +90,7 @@ cryptAcquireCtx =
90cryptGenRandom :: Word32 -> Int -> IO B.ByteString
90cryptGenRandom :: Word32 -> Int -> IO B.ByteString
91cryptGenRandom h i =
91cryptGenRandom h i =
92 BI.create i $ \c_buffer -> do
92 BI.create i $ \c_buffer -> do
93− stat <- c_cryptGenRandom (fromIntegral h) (fromIntegral i) c_buffer
93+ stat <- c_cryptGenRandom h (fromIntegral i) c_buffer
94 if (toBool stat)
94 if (toBool stat)
95 then return ()
95 then return ()
96 else fail "c_cryptGenRandom"
96 else fail "c_cryptGenRandom"
@@ -113,6 +113,7 @@ openHandle = do
113 liftM CH cryptAcquireCtx
113 liftM CH cryptAcquireCtx
115-- |Close the `CryptHandle`
115-- |Close the `CryptHandle`
116+closeHandle :: CryptHandle -> IO ()
116closeHandle (CH h) = cryptReleaseCtx h
117closeHandle (CH h) = cryptReleaseCtx h
118-- |Read from `CryptHandle`
119-- |Read from `CryptHandle`